0% found this document useful (0 votes)
173 views

Operators Questions

The document contains 5 Java programs with questions about the output of each. (i) Calculates (x * y / x) and (x * (y / x)), which will both output 5 since multiplication and division take precedence over addition/subtraction. (ii) Checks various conditional statements to print different outputs based on the values of variables x, y, and z. (iii) Performs a series of variable assignments and arithmetic operations to modify the values of variables x, y, and z, printing the final values. (iv) Contains a complex mathematical expression combining variables and operations, printing the result. (v) Calculates two expressions involving multiplication, division, and variables,

Uploaded by

sdgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views

Operators Questions

The document contains 5 Java programs with questions about the output of each. (i) Calculates (x * y / x) and (x * (y / x)), which will both output 5 since multiplication and division take precedence over addition/subtraction. (ii) Checks various conditional statements to print different outputs based on the values of variables x, y, and z. (iii) Performs a series of variable assignments and arithmetic operations to modify the values of variables x, y, and z, printing the final values. (iv) Contains a complex mathematical expression combining variables and operations, printing the result. (v) Calculates two expressions involving multiplication, division, and variables,

Uploaded by

sdgs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

OPERATORS QUESTIONS

[email protected]
Question : What will be the output of the following programs :

(i)
public class Test {
public static void main(String[] args){
int x = 2, y = 5;

int exp1 = (x * y / x);


int exp2 = (x * (y / x));

System.out.print(exp1 + “ , ”);
System.out.print(exp2);
}
}

(ii)
public class Test {
public static void main(String[] args) {
int x = 200, y = 50, z = 100;
if(x > y && y > z){
System.out.println("Hello");
}
if(z > y && z < x){
System.out.println("Java");
}
if((y+200) < x && (y+150) < z){
System.out.println("Hello Java");
}
}
}
(iii)
public class Test {
public static void main(String[] args){

[email protected]
int x, y, z;
x = y = z = 2;
x += y;
y -= z;
z /= (x + y);
System.out.println(x + " " + y + " " + z);
}
}

(iv)
public class Test {
public static void main(String[] args){
int x = 9, y = 12;
int a = 2, b = 4, c = 6;

int exp = 4/3 * (x + 34) + 9 * (a + b * c) + (3 + y * (2 + a)) / (a + b*y);

System.out.println(exp);
}
}

(v)
public class Test {
public static void main(String[] args){
int x = 10, y = 5;

int exp1 = (y * (x / y + x / y));


int exp2 = (y * x / y + y * x / y);

System.out.println(exp1);
System.out.println(exp2);
}
}

You might also like