google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 WAP to sum of two Numbers in Java

WAP to sum of two Numbers in Java

0

 

# 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


#WAP to sum of two Numbers in Java Using Buffered Reader

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

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top