Question
Program to swap two numbers.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class Swap_With
{
public static void main(String[] args)
{
int a, b, temp;// a and b are to swap
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a and b");
a = sc.nextInt();
b = sc.nextInt();
System.out.println("before swapping numbers: Value of a: "+a +" Value of b: "+ b);
/*swapping */
temp = a;
a = b;
b = temp;
System.out.println("After swapping: Value of a: "+a +" Value of b: "+ b);
System.out.println( );
}
}
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale