Java program to swap two numbers

Java program to swap two numbers

class Swap
{
public static void main(String…s)
{
int a,b,temp;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);

System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b);

temp=a;
a=b;
b=temp;

System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b);
}
}

3 thoughts on “Java program to swap two numbers

  1. umarkhan

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package convertbinary;

    public class Convertbinary {

    public static void main(String…s) {

    int a;
    int b;
    int temp;
    a=Integer.parseInt(s[0]);
    b=Integer.parseInt(s[1])

    System.out.println(“nBefore swap:n”+”a=”+a+”tb=”+b);
    temp=a;
    a=b;
    b=temp;
    System.out.println(“nafter swap:n”+”a=”+a+”tb=”+b);

    }
    }
    Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0
    at convertbinary.Convertbinary.main(Convertbinary.java:36)
    Java Result: 1

    Reply
  2. AASTHA

    Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0

    shows error

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *