Lab Exeception
Lab Exeception
public NegativeNumberException() {
class Exercise3 {
if (number < 0) {
return Math.sqrt(number);
try {
} catch (NegativeNumberException e) {
}
}
Question No: 2
import java.util.InputMismatchException;
import java.util.Scanner;
public NegativeValueException() {
try {
int N = scanner.nextInt();
if (N < 0) {
int sum = 0;
int count = 0;
try {
count++;
} catch (InputMismatchException e) {
if (count > 0) {
} else {
} catch (NegativeValueException e) {
scanner.close();
Lab Tasks
Question No: 1
import java.util.InputMismatchException;
import java.util.Scanner;
public NegativeNumberException() {
super("Cannot calculate square root of a negative number.");
try {
if (number < 0) {
} catch (NegativeNumberException e) {
} catch (InputMismatchException e) {
scanner.close();
Question No: 2
package task2;
import java.util.Scanner;
public AgeOutOfRangeException() {
public LowGpaException() {
try {
try {
} catch (LowGpaException e) {
} catch (AgeOutOfRangeException e) {
} catch (Exception e) {
scanner.close();