WAP in Java to calculate the sum of two numbers. The numbers are x=45 and y=56
Answers
Answered by
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:
- Line 1: Creates a class.
- Line 2: Creates the main() function.
- 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.
- Line 4: s is now the sum of x and y.
- Line 5: Displays the sum of x and y.
- Line 6: End of main().
- Line 7: End of class.
See the attachment for output.
Attachments:
Similar questions
Math,
1 month ago
CBSE BOARD X,
1 month ago
Math,
3 months ago
English,
3 months ago
Social Sciences,
9 months ago
Math,
9 months ago