Write a program that inputs two numbers, swaps the values and then displays them.

public static void main(String[] args) {

Scanner n=new Scanner(System.in);

int a, b,c;

System.out.println(“Enter 1st Values”);

a= n.nextInt();

System.out.println(“Enter 2nd Values”);

b=n.nextInt();

c=a;

a=b;

b=c;

System.out.println(“1st value is=”+a);

System.out.println(“2nd value is=”+b);

}

}

Output

Enter 1st Values

3

Enter 2nd Values

5

1st value is=5

2nd value  is=3

Leave a Reply

Your email address will not be published. Required fields are marked *