write a program to input three numbers and swap them as this: first number becomes the second number, second number becomes the third number and the third number becomes the first number.
Answers
Answered by
5
- write a program to input three numbers and swap them as this: first number becomes the second number, second number becomes the third number and the third number becomes the first number.
The given code is written in Java Language.
import java.util.*;
class Swap
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of a: ");
int a=sc.nextInt();
System.out.print("Enter the value of b: ");
int b=sc.nextInt();
System.out.print("Enter the value of c: ");
int c=sc.nextInt();
System.out.println("Before swapping, ");
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("c: "+c);
int d=a;
a=b;
b=c;
c=d;
System.out.println("After swapping, ");
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("c: "+c);
}
}
Similar questions