Computer Science, asked by lathasp85, 4 months ago

write a program to input 2integer (say a and b) and interchange there and display the result in java ​

Answers

Answered by sandipkeshri765
2

Answer:

import java.util.Scanner;

public class interchange

{

public static void main(String args[ ])

{

Scanner Sc = new Scanner (System.in);

System.out.println ("Enter the first number");

int n1 = Sc.nextInt ();

System.out.println("Enter the second number");

int n2 = Sc.nextInt ();

int n3 = n1+n2;

n1 = n3-n1;

n2 = n3 - n2;

System.out.println ("first number after interchange is " +n1);

System.out.println ("second number after interchange is" + n2);

}

}

Explanation:

there are many logic to solve this program but I think this one is easy , simple , and understable logic.

Similar questions