What is a string? correct answers an object storing a sequence of text characters
What are indexes? correct answers Characters of a string are numbered with 0-based indexes
What is the first character's index in a string? correct answers 0
What is the last character's index in a string? correct answers 1 less than the string's length
What is a nested loop? correct answers a loop placed inside another loop
Write a nested for loop to produce this output efficiently:
*****
*****
***** correct answers for (int I = 1; I <= 3; I++) {
for (int j = 1; j <= 5; j++) {
System.out.print("*");
}
System.out.println();
}
What is the output for the following nested for loop?
for (int I = 0; I < 5; I++) {
System.out.print("*");
for (int j = 0; j < I; j++) {
System.out.print(j);
}
,System.out.print("*");
} correct answers **
*0*
*01*
*012*
*0123*
What is the output of the following nested for loop?
for (int I = 1; I <= 5; I++) {
for (int j = 1; j <= 5 - I; j++) {
System.out.print(I);
}
System.out.println();
) correct answers 1111
222
33
4
What is scope? correct answers The part of a program where a variable is said to exist.
What happens when a variable is declared in a for loop? A method? correct answers That
variable exists only in that loop. Only exists in that method
What are the three scopes of interest to us? and what do they do? correct answers Block scope-
used with a for-loop and other java constructs that use blocks
Local scope- used within a method
class scope- used within all methods contained in a class
, Can variables that don't have overlapping scopes have the same name? correct answers Yes
Can a variable be declared twice in the same scope? Can it be used outside its declared scope?
correct answers No and no.
What is a parameter? correct answers A value passed to a method by its caller
What does a static method require in order for it to run? correct answers It requires a parameter
Write the basic form of declaring a parameter and give an example correct answers Public static
void name (type paramname) {
statement(s);
}
example:
public static void sayPassword(int code) {
System.out.orintln("The password is: " + code);
}
What is the output of this code, what does it do and why is it useful?
public static void main(String[] args) {
chant(3);
}
public static void chant(int times) {
for (int I = 1; I <= times; I++) {
System.out.println("Just a salad....");