Questions List
Browse all explanatory questions of this chapter.
1
Given the value of a variable, write a statement, without using if construct, which will produce the absolute value of the variable.
2
Question:
Rewrite the following fragment using switch:
if (ch == 'E') eastern++;
if (ch == 'W') western++;
if (ch == 'N') northern++;
if (ch == 'S') southern++;
else unknown++;
3
What is the problem of dangling-else?
When does it arise?
What is the default dangling-else matching, and how can it be overridden?
4
Question:
Given the following code fragment:
if (a == 0) System.out.println("Zero");
if (a == 1) System.out.println("One");
if (a == 2) System.out.println("Two");
if (a == 3) System.out.println("Three");
Write an alternative code (using if) that saves on the number of comparisons.
5
Write a difference between class and a object
6
Comparison between if-else if and switch-case
7
Break statement can be used as labels in Java?
8