Professional Documents
Culture Documents
Lab 08
Lab 08
Lab 08
Practical # 8
Objective
Tools
Notepad++/CMD.
Write a Program that prompts the user to read Two Integers and Displays their Sum.
Program should prompt the user to read the number again if the input is incorrect (i.e. user
enters word or float point number).
import java.util.*;
}
}
OUTPUT
Write a Program that causes the JVM to throw an OutOfMemoryError and catches and
handles this error.
OUTPUT
Write a program that creates two classes, NoMatchException and TestException.
NoMatchException is a user-defined exception and TestException simply uses it.
TestException takes the input from the user and throws the object of NoMatchException if
the user provides “OOP” as input.
import java.util.Scanner;
class TestException {
public void userInput() throws NoMatchException {
Scanner sc = new Scanner(System.in);
if (input.equals("OOP")) {
throw new NoMatchException("Input matches 'OOP'");
} else {
System.out.println("Input: " + input);
}
}
}
Timelines
Date: _______________