int number = 20;
if(number > 15){
System.out.println("Welcome to Java");
}
Welcome to Java
Name the three types of loops
While Loop, Do While Loop, and For Loop
What two symbols are used in every method
() The left and right parenthesis.
What is an example of a line that doesn't end with a semicolon?
Loops, or the opening class block.
while(5 > 4){
System.out.println("hello");
}
Infinite Loop
The if statement is an example of a _____.
a. sequence structure
b. decision structure
c. pathway structure
d. class structure
b. decision structure
What is the best type of loop to use when you know exactly how many times you want the loop to run
For loop
Does this line of code contain a method?
Int number = input.nextInt();
Yes, the nextInt() part of the code is a method.
What is missing from this code?
While{
System.out.println("Welcome to Java");
}
The condition for the while loop
Scanner input = new Scanner();
String userInput = input.nextInt();
>, <, and == are _____.
a. relational operators
b. decision expression
c. unconditional expression
d. boolean expression
a. Relational operators
What is the sentinel value in this loop example.
System.out.println("Please keep typing integers until you are done, then type 0 to stop");
0 since it is the number used to end the loop.
What is the output of this method
String name = "Donald";
System.out.println(name.indexOf("o"));
It will print 1 since the first instance of o is in the one index.
What are the possible outputs of this number
int rand = (int)(Math.random() * 10 + 1);
1 through 10
String word = "hello";
System.out.println(charAt.word(4));
charAt and word should be switched
int number = 20;
if(number < 15){
System.out.println("Welcome to Java");
}
else if(number <= 18){
System.out.println("Welcome to Java");
}
else{
System.out.println("Try again later");
}
Try again later
What will be the last output of this for loop?
for(int i = 0; i < 10; i++){ System.out.println("Welcome to count number " + i);
}
Welcome to count number 9
What method do we use when we want to create a substring from a string named "word"
word.substring
What is the output of this line of code.
System.out.println((int)(2.0 + 5 + 3.0));
10 because it's being cast to an int
for(int i, i < 5, i++){
System.out.println("Good luck on the test!");
}
Semicolons should be used instead of commas to separate parts of the for loop.
What is the difference between the "else if" and "else" statements.
Else if is used to add another option whereas else is used as a final option that happens if all others fail.
What is the ouput of this code
int i = 0;
do{
System.out.println("Hello");
i++;
}
while(i > 10);
The word hello once because the condition isn't met.
What does this print?
String s = "marco polo";
System.out.println(s.substring(0,3));
mar
What is the difference between a logic error and a runtime error.
A logic error is when the code runs but gives you an incorrect output. A runtime error is when the code crashes during runtime due to an error.
int counter = 0;
do while(counter < 10){
System.out.println("The count is at " + counter);
counter ++;
}