Computer Applications
What will be the output of the following code?
int x=2,y=5,a=0;
a=x;
x=y;
y=a;
System.out.println("x=" + x + "
y=" +
y);
Java Conditional Stmts
5 Likes
Answer
Output is:
x=5 y=2
This code is swapping the values of x and y.
Answered By
1 Like
Related Questions
Find the errors in the following code and rewrite the correct version:
char m="A"; Switch ("A"); { Case 'a'; System.out.println("A"); break; Case 'b'; System.out.println("B"); break; Default: System.out.println("Not a valid option"); }
Rewrite the following statement using if else:
int max=215, min=323; String str= (max>min) ? "Max is greater than Min" : "Min is Greater than Max";
Write a program to find the number of and sum of all integers greater than 500 and less than 1000 that are divisible by 17
What will be the value of 'n' after the execution of the code given below?
int x=2, m=1, c=-1; int n = x + c; n = n - c + x; System.out.println(n);