Lab 12 Exception Handling
Lab 12 Exception Handling
EXCEPTION HANDLING
QUESTION NO:1
[8:59 AM, 9/25/2019] javeriashakil999: Refining Your Calculator: Your primary task
for this lab is to restructure your calculator to handle exceptions. You can put the
method in a try catch clause.
class Excp
int a,b,c;
try
a = 0;
b = 10;
c = b/a;
catch(ArithmeticException e)
{
System.out.println("Divided by zero");
output
zeroDivided by
QUESTION NO:2
* ■ Prompts the user to enter the index of the array, then displays the *
***************************/
import java.util.*;
// Create a Scanner
Scanner input = new Scanner(System.in);
try {
array[input.nextInt()]);
System.out.println("Out of Bounds.");
return array;
OUTPUT
Out of Bound:4
QUESTION NO:3
Write a program that accepts a test score, that is, a positive integer in the range 0
through 100 inclusive, and displays an equivalent letter grade: A (90), B (80–89), C
(70–79), D (60–69), F (under 60). Throw an exception if the mport
java.util.Scanner;
int A_grades = 0;
int B_grades = 0;
int C_grades = 0;
int D_grades = 0;
int F_grades = 0;
int count=0;
while(score>0)
count++;
A_grades++;
B_grades++;
C_grades++;
D_grades++;
F_grades++;
score = in.nextInt();
} //end while
} // end main
} // end class
88 98 78 68 55 45 -1
In the output it keeps repeating "Enter exam score as integer percentage in range
0 to 100.