Friday, October 29, 2010
Eksekutif.Java 2
1. What is the answer for Math.sqrt(-9)?
a. -3 b. 3 c. 81 d. NaN
2. What is the output of the following statement?
int iNum = 12;
double dNum = iNum/10;
System.out.println(iNum + " " + dNum);
a. 12 1.2 b. 12.0 1.0 c. 12 1.0 d. 12.0 1.2
3. What is the output of the following statement?
int iNum = 12;
double dNum = (double) iNum/10;
System.out.println(iNum + " " + dNum);
a. 12 1.2 b. 12.0 1.0 c. 12 1.0 d. 12.0 1.2
4. Which of the following is NOT a relational (comparison) operator in Java?
a. = b. != c. >= d. <=
5. The result of the boolean expression 3 + 5 <= 8 is
a. true b. false c. 0 d. The expression will generate a compile error
6. The result of the boolean expression 'B' < 'a' is
a. true b. false c. 0 d. The expression will generate a compile error
7. The result of the boolean expression '3' < 'C' is
a. true b. false c. 0 d. The expression will generate a compile error
8. The result of the boolean expression 3 < '3' is
a. true b. false c. 0 d. The expression will generate a compile error
9. Which of the following contains only relational operators?
a. = < > b. <= >= ==
c. =< >= == d. < <> >
10. Consider the following code fragment:
sc refers to an instance of Scanner class, which is created as:
Scanner sc = new Scanner (System.in);
int x = sc.nextInt();
if (x >= 0)
System.out.println("The input is ") ;
System.out.println(x);
Which of the following statements is true?
The value of x always gets printed out.
The value of x gets printed out only when the input is positive or zero.
The value of x gets printed out only when the input is negative.
The value of x never gets printed out.
11. What will be the value of num after the following section of code executes:
int num = 15;
if (num > 10)
num = num * 2;
else
num = num - 2;
a. 8 b. 13 c. 20 d. 30
12. The output for the following fragment code is
int num = 11;
if (num >= 10)
num = num / 2;
System.out.println(num);
System.out.println("Done");
a. Done b. 5 c. 5.5 d. 11
Done Done Done
13. What will the following code print?
int code = 321 % 4;
if (code == 0)
System.out.println("KL");
else if (code == 1)
System.out.println("PJ");
else if (code == 2)
System.out.println("SA");
else
System.out.println("Klang");
}
a. KL b. PJ c. SA d. Klang KL
14. Consider the following code fragment:
sc refers to an instance of Scanner class, which is created as:
Scanner sc = new Scanner (System.in);
int x;
x = sc.nextInt() ;
if (x >= 0)
System.out.println("positive input:");
System.out.println(x);
else
System.out.println("negative input:");
System.out.println(x);
Which of the following statements is true?
The code fragment will not compile.
If the value entered for x is zero no output occurs.
If the value entered for x is positive, "positive input:" is displayed, followed by the value of x, displayed once.
If the value entered for x is positive, "positive input:" is displayed, followed by the value of x, displayed twice.
Labels:
Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment