Computer Science, asked by ksss50094p9j8lr, 8 months ago

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 anindyaadhikari13
5

\star\:\:\:\sf\large\underline\blue{Question:-}

  • 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.

\star\:\:\:\sf\large\underline\blue{Code:-}

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