Write a program to take two numbers as input then display their total using java.io. package for input i.e. InputStreamReader isr= new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
Integer.parseInt(br.readLine());
Use void only once in public static void main(String args[])
Don't use void second time.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int total;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
System.out.print("Enter number 1: ");
int n1 = Integer.parseInt(br.readLine());
System.out.print("Enter number 2: ");
int n2 = Integer.parseInt(br.readLine());
total = n1 + n2;
System.out.println("Total: " + total);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
in.close();
}
}
Comments
Leave a comment