Make the following programs:
1. To input any two numbers and print their sum, and product by leaving two lines in between
2. To accept values of two numbers and interchange their values.
Answers
Answered by
1
Answer:
Program 1
import java.util.*;
public class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a,b,sum, product;
System.out.println("Enter the 2 numbers");
a=in.nextInt();
b=in.nextInt();
sum=a+b;
product=a*b;
System.out.println("The sum of the numbers="+sum);
System.out.println();
System.out.println();
System.out.println("The product of the numbers="+product);
}
}
Program 2
import java.util.*;
public class Num
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a,b;
System.out.println("Enter the value of a");
a=in.nextInt();
System.out.println("Enter the value of b");
b=in.nextInt();
System.out.println("a="+b);
System.out.println("b="+a);
}
}
Similar questions