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);
}
}

6 thoughts on “Java program to swap two numbers”

  1. Edgar Aguilar Mota

    hello i am student programmner and i need to someone help me
    i can´t to do any proyect, i really want to learn.

  2. /*
    * 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

Leave a Comment

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