This escape sequence represents a line-feed.
\n
This is the index of the first character in a string.
0
System.out.printf("Hello", 1234);
Hello
Number of parts in a for-loop declaration.
3
This is the name of a while-loop with a condition that never becomes false.
infinite loop
This is the result of character.isLetter('a')
An error
Character needs to be capitalized.
This method returns the size of String s1.
s1.length()
Each of these represents:
%d
%s
%c
%f
%b
%%
int
String
char
float/double
boolean
%
This type of loop will always execute at least once.
do-while loop
This is the name of a special input value that represents the end of input in a while-loop
sentinel value
The Unicode for 'B' is 66. This is the Unicode for 'G'.
71
This method is used to check if s1 is the same as s2.
s1.equals(s2)
Left or right justified?
System.out.printf("%03d", -10);
right justified
This type of loop is best for when you know the exact number of iterations beforehand.
for loop
This keyword is used to terminate the loop prematurely once a certain condition is met.
break
int i = 116;
This statement will print the character with the Unicode value stored in i.
System.out.println((char) i);
s1.compareTo(s2) == 0
We now know this about s1 and s2.
They are the same
The correct way to print a double num up to 4 decimal places.
System.out.printf("%.4f", num);
Number of iterations in the following nested loop
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
System.out.println(i);
}
}
20
This keyword is used to skip the rest of the current iteration and then proceed to the next one.
continue
We have a char variable called ch.
The following statement is checking:
(ch >= 'A' && ch <= 'Z')
If ch is capital
This is how we find out the last character in a String s1.
s1.charAt(s1.length() - 1)
Write a statement that will take the number 10.3456 and formats it at least 8-wide, right-justified, 0-filled, and rounded to the nearest hundredth. End it with a line break.
System.out.printf("%08.2f\n", 10.3456);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
continue;
}
System.out.print(i + " ");
}
The odd numbers 1-9
For each of the loop types below, state whether they can perform counter, sentinel, and flag-controlled loops.
A. for loops
B. while loops
C. do-while loops
for loops: counter
while loops: counter, sentinel, and flag
do-while loops: counter, sentinel, and flag