The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be greater than or equal to 100. The array can only hold 100 elements – Add a finally clause which prints the entries in the Array. – Print 20 elements on each line of output. See the sample output.
import java.util.*;
public class ExceptionLab {
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
int [] numbers = new int [100];
for (int i = 0; i < 100; i++)
{
numbers [i] = (int)(Math.random() * 100 + 1);
}
System.out.println("Enter an index value from 0 to 99");
int index = reader.nextInt();
//the statement following should be in the try clause
System.out.println( numbers [index]);
//add catch and finally
}
}
import java.util.*;
public class ExceptionLab {
public static void main(String[] args) {
Scanner reader = new Scanner (System.in);
int [] numbers = new int [100];
for (int i = 0; i < 100; i++)
{
numbers [i] = (int)(Math.random() * 100 + 1);
}
System.out.println("The Array has been filled with random numbers");
System.out.println("Enter an index value from 0 to 99");
int index = reader.nextInt();
//the statement following should be in the try clause
try{
System.out.println( "The element at the index "+index+" is "+numbers [index]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Index value cannot be greater than or equal to 100\nArray contains 100 elements");
}
finally{
System.out.println("The Array");
for(int i=0;i<numbers.length;i++){
if(i%20==0 && i!=0) System.out.print("\n");
System.out.print(numbers[i]+" ");
}
}
}
}
The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...
Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...
Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...
1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...
Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...
2.29 The following is the C codes and the translated MIPS codes. Assume that the C-level integers t1 and a0 are held in register $t1 and $a0, and $s0 holds the base address of the integer MemArray. void foo () { int MemArray[100] = { 96, 98, 63, 69, 42, 27, 16, 6, 47, 74, 44, 33, 76, 7, 88, 33, 80, 86, 86, 64, 17, 67, 60, 51, 2, 61, 93, 87, 49, 98, 24, 98, 30, 65, 2,...
Use the accompanying data set on the pulse rates (in beats per minute) of males to complete parts (a) and (b) below. LOADING... Click the icon to view the pulse rates of males. a. Find the mean and standard deviation, and verify that the pulse rates have a distribution that is roughly normal. The mean of the pulse rates is 71.871.8 beats per minute. (Round to one decimal place as needed.) The standard deviation of the pulse rates is 12.212.2...
I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....
I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...
Question 1 15 pts Test scores for a class of 40 students are listed below: 25 35 43 44 47 48 54 55 56 57 59 62 63 65 66 68 69 69 71 72 72 73 74 76 77 77 78 79 80 81 81 82 83 85 89 92 93 94 97 98 a) The mean of the sample data is b) The median of the sample data is c) The standard deviation of the sample data is...
Use the pulse rates in beats per minute (bpm) of a random sample of adult females listed in the data set available below to test the claim that the mean is less than 74 bpm. Use a 0.01 significance level. Pulse Rate (bpm) 60 87 93 92 95 62 92 93 71 67 35 84 54 68 74 36 72 67 100 61 52 42 58 104 67 102 83 95 73 76 38 42 55 85 38 99 84...