Page 183 - ComputerScience_Class_11
P. 183
2. Write a program that asks the user to input two numbers and then compares them using relational operators. The program
should output the results of the comparisons.
Enter first number: 15
Enter second number: 10
a == b : false
a != b : true
a > b : true
a < b : false
a >= b : true
a <= b : false
3. Write a program that finds the largest number among three given numbers using a nested ternary operator.
Enter first number: 10
Enter second number: 20
Enter third number: 15
The largest number is: 20
G. Find the output of the following programs:
1. class CodeOutput1 {
public static void main(String[] args) {
int a = 5, b = 10;
int result = a++ + ++b + a;
System.out.println("a: " + a);
System.out.println("b: " + b);
System.out.println("Result: " + result);
}
}
2. class CodeOutput2 {
public static void main(String[] args) {
int x = 8, y = 3;
x += ++y + x--;
System.out.println("x: " + x);
System.out.println("y: " + y);
}
}
3. class CodeOutput3 {
public static void main(String[] args) {
int p = 10, q = 20;
boolean result = (p < q) && !(p > 5) || (q == 20);
System.out.println("Result: " + result);
}
}
Variables and Expressions 181

