發新話題
打印

Java swap two numbers

Java swap two numbers

Swap two Numbers


import java.util.Scanner;
class Swapnumber {
    public static void main(String[] args) {
        int a, b, c;
        Scanner s = new Scanner(System.in);
        System.out.println("Enter Value in a :");
        a = s.nextInt();
        System.out.println("Enter Value in b :");
        b = s.nextInt();
        c = a;
        a = b;
        b = c;
        System.out.println("Values in a:" + a);
        System.out.println("Values in b:" + b);
    }
}

Output:
Enter Value in a : 10
Enter Value in b : 20
Value in a : 20
Value in b : 10

TOP

發新話題