Answer the following questions as briefly (but completely) as possible:
boolean b = true;
int i = (int) b;
int i = 1;
boolean b = (boolean) i;
int i = 1;
String s = (String) i;
number
is 30? If number is 35?
if (number % 2 == 0)
System.out.println(number + " is even.");
System.out.println(number + " is odd.");
if (number % 2 == 0)
System.out.println(number + " is even.");
else
System.out.println(number + " is odd.");
i such that
0 ≤ i < 20? 10 ≤ i < 20? 10 ≤ i ≤ 50? ch is a char):
(ch >= 'A' && ch <= 'Z')
ch is 'A'? ch is 'p'? ch is 'E'? ch is '5'? String variable
dayName with Sunday, Monday,
Tuesday, Wednesday, Thursday,
Friday, and Saturday, if the int
variable day is 0, 1, 2,
3, 4, 5, and 6, accordingly.
for loop on the left is converted into the while
loop on the right. What is wrong? Correct it.
int sum = 0;
for (int i = 1; i <= 4; i++) {
if (i % 3 == 0) continue;
sum += i;
} |
int i = 1, sum = 0;
while (i <= 4) {
if (i % 3 == 0) continue;
sum += i;
i++;
} |
int sum = 0;
for ( int i = 0; i < 10; ++i ) {
sum += i;
}
int sum = 0;
for ( int i = 0; i < 10; i++ ) {
sum += i;
} break statement is executed in the following
loop, which statement is executed? Show the output.
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 4; j++) {
if (i * j > 2)
break;
System.out.println(i * j);
}
System.out.println(i);
} continue statement is executed in the following
loop, which statement is executed? Show the output.
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 4; j++) {
if (i * j > 2)
continue;
System.out.println(i * j);
}
System.out.println(i);
}
System.out.printf("%5d %d", 1, 2, 3); System.out.printf("%5d %f" , 1); System.out.printf("%5d %f" , 1, 2); System.out.printf("amount is %f %e\n" , 32.32, 32.32); System.out.printf("amount is %5.4f %5.4e\n", 32.32, 32.32); System.out.printf("%6b\n", (1>2)); System.out.printf("%6s\n", "Java"); System.out.printf("%-6b%s\n", (1>2), "Java"); System.out.printf("%6b%-s\n", (1>2), "Java"); System.out.printf("%6b%-8s\n", (1>2), "Java"); | Input | Result From Correct Regex |
|---|---|
| ,0 | False |
| , | False |
| 1,20 | False |
| 1,234, | False |
| 0 | True |
| 12 | True |
| 123 | True |
| 1,234 | True |
| 0,000 | True |
| 100,000 | True |
Email your homework assignment, by copy-and-paste (no attachments please), to (homework submission). If possible use the “text” and not the “HTML” mode of your email program. Please use the subject similar to “Java Programming I Homework Assignment #2 Submission”, so I can tell which emails are submitted homework assignments.
Homework assignments will not be returned. Please do not send as attachments. Refer to the Homework and the Submitting Assignments sections of your syllabus for more information.
Confused? Send questions about the homework assignment to (homework questions). Please use a subject similar to “Java Programming I Homework Assignment #2 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).