Documente Academic
Documente Profesional
Documente Cultură
2.
3.
if (number <= 0)
System.out.println(number);
System.out.println(number);
a.
b.
c.
d.
e.
4.
number
number
number
number
All of
5.
1
-1
0
None of the above
6.
Which
a.
b.
c.
d.
e.
of
(1
(x
(x
a,
a,
7.
8.
x >= 1
!(x <= 1)
!(x = 1)
!(x < 1)
None of the above
switch (d + 4) {
case 5: x++;
case 6: --x;
}
a.
The required break keyword is missing in the switch
statement.
b.
The required default keyword is missing in the switch
statement
c.
The switch control variable cannot be double
d.
a, b, and c are all correct.
e.
a, b, and c are all incorrect.
10.
a.
b.
c.
d.
if (x > 0)
{
System.out.println("x");
}
The symbol x is always printed.
The value of variable x is always printed.
Nothing is printed because x > 0 is false.
None of the above.
11.
Which
least once.
a.
b.
c.
d.
12.
a.
b.
c.
d.
e.
13.
The
The
the
The
not
The
The
14.
15.
9
10
c.
d.
e.
11
12
None of the above.
16.
-1
0
1
2
The loop does not end
1
0
1
2
None of the above
2
3
4
None of the above
The program
The program
The program
The program
None of the
(A)
(B)
a.
b.
c.
d.
if (i > 0) if
(j > 0)
x = 0; else
if (k > 0) y = 0;
else z = 0;
Part III. (5 pts) Identify and fix errors in the following code:
public class Test
{
public static void main(string[] args)
{
for (int i = 0; i < 10; i++);
{
if (j > i) then
j++
else
j--;
}
}
}
2.
1 2 3
98 99
...
2 3 4
99 100
10
1bb
1bb3bb
1bb3bb9bb
1bb3bb9bb27bb
Part V:
(a)
import javax.swing.JOptionPane;
public class Test {
/**Main method*/
public static void main(String[] args) {
// Prompt the user to enter sales amount
String doubleString = JOptionPane.showInputDialog(
"Enter sales amount:");
// Convert string to double
double salesAmount = Integer.parseInt(doubleString);
// Compute sales commission
double salesCommission = 0;
if (salesAmount <= 5000)
salesCommission = salesAmount * 0.08;
else if (salesAmount <= 10000)
salesCommission = 5000 * 0.08 + (salesAmount - 5000) * 0.1;
else
salesCommission = 5000 * 0.08 + 10000 * 0.1 +
(salesAmount - 10000) * 0.12;
// Display results
System.out.println("Sales commission is " + salesCommission +
" for sales amount of " + salesAmount);
}
(b)
import javax.swing.JOptionPane;
public class Test {
/**Main method*/
public static void main(String[] args) {
double sum = 0;
for (int i = 1; i <= 99; i++)
sum += sum + (i * 1.0 / (i + 1));
// Display results
System.out.println("Sum is " + sum);
11
(c)
public class Test {
/**Main method*/
public static void main(String[] args) {
for (int row = 1; row <= 9; row++) {
// Print spaces
for (int column = 1; column < row; column++)
System.out.print(" ");
for (int column = row; column <= 9; column++)
System.out.print(column);
for (int column = 8; column >= row; column--)
System.out.print(column);
}
System.out.println();
}
}
12