This data type holds true or false values
What is a boolean?
boolean done = false;
if(!done)
System.out.println("Yea");
else
System.out.println("Nah");
What is Yea?
What is the return type of
public static void printNumber(int x) ?
What is void?
String word = "frenzy!";
System.out.println(word.charAt(6));
What is ! ?
String [ ] veggies = {"celery","carrots","mushrooms","peppers"};
System.out.println(veggies.length);
What is 4?
This is 27 % 8
What is 3?
int x = 17;
int y = -3;
boolean huh = y <= x && x != y;
System.out.println(huh);
This method is used to control the order of commands in a running program.
What is the main method?
int num = "abc".indexOf("z");
System.out.println(num);
What is -1 ?
String [ ] veggies = {"celery","carrots","mushrooms","peppers"};
System.out.println(veggies[2]);
What is mushrooms?
int x = 11;
String animal = "dog";
System.out.println("I have " + x + " " + animal + "s!");
What is I have 11 dogs!
What is the error in the code segment?
Scanner kb = new Scanner(System.in);
System.out.println("Enter a number");
int x = kb.nextLine( );
What is nextLine( )?
This is the parameter list of:
public static double doSomething(int x; String y)
What is int x and String y?
String fruit = "banana";
System.out.println(fruit.substring(1,4));
What is ana ?
int [ ] pi = {3, 1, 4, 1, 5, 9, 2};
for(int i = 0; i < 4; i++)
System.out.println(pi[i]);
What is 3141?
System.out.println(5/10);
What is 0?
This nested loop runs that many times:
for(int i = 0; i < 5; i++)
for(int j = 0; j < 7; j++)
System.out.println("*");
What is 35?
This command is a random number from 3 to 7
What is (int)(Math.random( ) * 5) + 3
String greeting = "hi";
String other = "high";
greeting += "gh";
System.out.println(greeting.equals(other));
What is true?
boolean [ ] truths = new boolean [7];
for(int i = 0; i < truths.length; i += 2)
System.out.print("*");
What is **** ?
System.out.println("" + 5 + 2);
What is 52?
int x = 5;
while(x < 7)
{
System.out.println("???");
}
What is an infinite loop?
This is a method that takes in a double and rounds the value to the nearest hundredth place.
What is
public static double roundNearest(double x)
{
return Math.round(x * 100) / 100.0;
}
String word = "knickknack";
String newWord = "";
for(int x = 0; x < word.length(); x++) {
if (word.charAt(x) == 'k')
newWord += '$';
else
newWord += word.charAt(x);
}
System.out.println(newWord);
What is $ni$$nac$ ?
String [ ] veggies = {"celery","carrots","mushrooms","peppers"};
System.out.print(veggies[3].substring(0,4) + " ");
System.out.print("in my step!");
What is pep in my step! ?