Computer Science, asked by yashashishpro, 3 months ago

WAP in Java to calculate the sum of two numbers. The numbers are x=45 and y=56

Answers

Answered by anindyaadhikari13
1

Answer:

This is the required Java program for the question.

public class Sum  {

   public static void main(String args[])   {

       int x=45,y=56,s;

       s=x+y;

       System.out.println("Sum of "+x+" and "+y+" is: "+s);

   }

}

Explanation:

  1. Line 1: Creates a class.
  2. Line 2: Creates the main() function.
  3. Line 3: Declares the variables x, y and s. x and y contains the values 45 and 56. s is used for storing their sum.
  4. Line 4: s is now the sum of x and y.
  5. Line 5: Displays the sum of x and y.
  6. Line 6: End of main().
  7. Line 7: End of class.

See the attachment for output.

Attachments:
Similar questions