Write a Java program, in which you input 2 numbers and find the sum and product of the two number in java
Write a Java program, in which you input 2 numbers and find the sum and product of the two number in java
import java.util.Scanner;
public class SumProduct
{
public static void main(String args[]){
int num1,num2,product,sum;
Scanner input = new Scanner(System.in);
System.out.println("Enter the 1st number");
num1=input.nextInt();
System.out.println("Enter the 2nd number");
num2=input.nextInt();
sum=num1+num2;
product=num1*num2;
System.out.println("Sum of "+num1+" and "+num2+" is "+sum );
System.out.println("Product of "+num1+" and "+num2+" is "+product );
}
}
Output
Sum of 14 and 2 is 16
Product of 14 and 2 is 28
Comments
Post a Comment