Skip to main content

Java program to print the sum of two numbers.

class Sum{
public static void main(String args[]){
int a=45;
int b=36;
int sum;
sum=a+b;
System.out.println("Sum of two Numbers = "+sum);
}
}

Save as: Sum.java
Output:

Comments

Popular posts from this blog

Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.

import java.util.Scanner; class Exercise1{ public static void main(String args[]){ Scanner io=new Scanner(System.in); System.out.println("Enter the first number. = "); int num1=io.nextInt(); System.out.println("Enter the second number = "); int num2=io.nextInt(); int sum,mult,sub,div,rem; sum=num1+num2; mult=num1*num2; sub=num1-num2; div=num1/num2; rem=num1%num2; System.out.println("Sum of \t\t"+num1+" & "+num2+" = "+sum); System.out.println("Multiply of \t"+num1+" & "+num2+" = "+mult); System.out.println("Subtract of \t"+num1+" & "+num2+" = "+sub); System.out.println("Divide of \t"+num1+" & "+num2+" = "+div); System.out.println("Remainder of \t"+num1+" & "+num2+" = "+rem); } } Save as: Exercise1.java Output: