Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num == 'a') {
System.out.println("Good result !");
} else {
System.out.println("Result:" + num);
}
}
}
What is the result ? (choose one)
A Good result !
B Result:1
C Compilation fails
D An exception is thrown at runtime
Solution :
The result is C.There is no compilation error.You can compare 1 with 'a' because the comparison use the unicode value of a.So it's correct to compare 1 with 'a'.
Wednesday, January 27, 2010
SCJP exercise : operators
Wednesday, January 20, 2010
SCJP exercise : operators
An other exercise ! The goal is practice and learn commons java certification SCJP questions.
Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num = 2) {
System.out.println("Result:" + num);
}
System.out.println("Result:" + num);
}
}
What is the result ? (choose one)
A Result:1
B Result:2
C Compilation fails
D An exception is thrown at runtime
Solution :
The solution is C.In fact we set num to 2 with num=2.
So the result of the setting is an int.Or the if is waiting a boolean so the compilation fails.
Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num = 2) {
System.out.println("Result:" + num);
}
System.out.println("Result:" + num);
}
}
What is the result ? (choose one)
A Result:1
B Result:2
C Compilation fails
D An exception is thrown at runtime
Solution :
The solution is C.In fact we set num to 2 with num=2.
So the result of the setting is an int.Or the if is waiting a boolean so the compilation fails.
Thursday, January 7, 2010
Good year
Hi !
This year we will see many things like certification exercise, Java tips, Go langage ...
So it's exiting !
This year we will see many things like certification exercise, Java tips, Go langage ...
So it's exiting !
Subscribe to:
Posts (Atom)