Write a program to demonstrate the use of only throws
keyword.
$ javac Program.java
$ java Program
import java.lang.System;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Program {
// Here, `readLine` method from `java.io.BufferedReader` `throws` `IOException`.
// Thus, we need to `catch` it or use `throws` keyword in our method.
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
System.out.println("Entered String: " + input);
}
}
right-click & select “Open image in new tab” for larger image.