Computer Science, asked by ROYALPUBGGAMER, 9 months ago

WAP to interchange and print the values of two numebers in java​

Answers

Answered by nottysidhant
1

Explanation:

Java program to swap two numbers

import java.util.Scanner;

class SwapNumbers.

{

public static void main(String args[])

{

int x, y, temp;

System. out. println("Enter x and y");

Scanner in = new Scanner(System. in);

Answered by anindyaadhikari13
1

Question:-

  • Write a program in Java to swap two numbers.

Code:-

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.println("Before swapping, ");

System.out.println("a: "+a);

System.out.println("b: "+b);

int c=a;

a=b;

b=c;

System.out.println("After swapping, ");

System.out.println("a: "+a);

System.out.println("b: "+b);

}

}

Similar questions