SCJP Module-2 Question-20


 

SCJP Module-2 Question-20

The given program below checks your understanding of core Java program and their flow. The given program is also very useful for preparation for SCJP exams.

The given program below checks your understanding of core Java program and their flow. The given program is also very useful for preparation for SCJP exams.

Find the error in the given code :

1 public class Example20{
2 public static void main(String[] args){
3 int a = 0;
4 int b=2;
5 int c = 3;
6 if(a++) {
7 b = a * c;
8 a /= 2;
9 }else {
10 b = b * b;
11 ++c;
12}}}

Find the error in the given code : 

1. Error at line number 2

2.Error at line number 6

3.Error at line number 7

4..Error at line number 10.

Answer

(2)

Explanation :

Due to the code at line number 6, this code will not compile. Since " if " statement  takes 'Boolean' or 'conditional expression' as argument .

The output of the following program will be :

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from int to boolean

Ads