write a Java program to add two numbers - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, March 2, 2015

write a Java program to add two numbers



ALGORITHM:

Step 1: Read values for a and b.

Step 2: c=a+b

Step 3: print c

Step 4: Stop

PROGRAM: import java.io.*; class clsadd

{

public static void main(String args[])throws IOException

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int a,b,c;
a=Integer.parseInt(br.readLine());

b=Integer.parseInt(br.readLine());

c=a+b;

System.out.println("The Sum is "+c);}}

OUTPUT:

D:\JAVA>set path=c:\java\bin D:\JAVA>javacclsadd.java D:\JAVA>java clsadd

10

20


The Sum is 30 D:\JAVA>

Search ByStudents

Java Program To add 2 numbers
add 2 numbers in java

No comments:

Post a Comment