Write an algorithm to input 2 numbers and swap the values?
Answers
Answered by
2
Answer:
class Swap
{
public static void main (String.args[ ]);
{
int a = Sc.next Int ();
int b = Sc.next Int ();
a = a + b
b = a - b
a = a - b
S.O.P.ln (c)
}
}
Answered by
0
Answer:
Q/ Write an algorithm that inputs 2 numbers and swaps them.
Explanation:
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter the x: ");
int x=input.nextInt();
System.out.print("Enter the y: ");
int y=input.nextInt();
x=x+y;
y=x-y;
x=x-y;
System.out.println("x: "+x);
System.out.println("y: "+y);
}
Similar questions
Science,
4 months ago
Physics,
4 months ago
Computer Science,
4 months ago
Chemistry,
8 months ago
Geography,
8 months ago
Science,
11 months ago
Computer Science,
11 months ago