Answer to Question #295560 in Java | JSP | JSF for Ninera

Question #295560

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.


1
Expert's answer
2022-02-09T09:25:08-0500
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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS