OOPS

Assignment - 11

Objective

Write a program to demonstrate the use of only throws keyword.

Programming Language & Compilation

$ javac Program.java
$ java Program

Source Code

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);
  }
}

Output

right-click & select “Open image in new tab” for larger image.

WindowsTerminal_5Qz1AXFVIX