# WAP to sum of two Numbers in Java
import java.io.*;
class sum { public static void main(String args[]) { int a,b,c; a=10; b=20; c=a+b; System.out.print(“The Sum is =”+c); } }
|
Output:
The Sum is =30 |
import
java.io.*;
class
sum {
public static void main(String[] args) throws IOException { //
system.in reader (e.g. the input from the console)
InputStreamReader ISR = new InputStreamReader(System.in); //
buffer the console reader
BufferedReader BR = new BufferedReader(ISR);
//
the default values for the two numbers
int val1,val2; //
output the question.
System.out.print("Enter first number : ");
//
read in the console intput one line (BR.readLine) and then convert to a
integer
val1 = Integer.parseInt(BR.readLine());
System.out.print("Enter second number : ");
val2 = Integer.parseInt(BR.readLine());
//
output the answer of adding both of the values together
System.out.println("The Sum is = " + (val1 + val2)); } }
|
Output:
Enter First number: 20 Enter second number: 21 The Sum is =41 |
WAP to sum of two Numbers in Java
Monday, August 28, 2017
0
Tags
Share to other apps