System.out.println("Hello World");
Hello World
This type can include words or sentences
String
How do I create a class called Car?
class Car
or
class Car{
//code
}
What library should I import if I want to generate a random number?
The random library
or java.util.Random
Fix this line of code so it prints Hello World
System.out.println(Hello World);
System.out.println("Hello World")
System.out.println("5" + "5");
55
What can x be equal to?
boolean x;
true or false
The method that allows a class to create an instance of itself is called what?
The constructor
What is 11%22 equal to?
11
which line of code causes an error?
int [] x = new int [5];
x[5] = 1;
x[4] = 2;
x[3] = 3;
x[5] = 1;
float x = 20;
System.out.println(x);
20.0
Fill in the blank:
___ x = 'c';
char
I have an object called duck and I want to call an instance method called fly with it. How do I do this?
duck.fly();
What must x be to make z true
boolean x = ___
boolean y = true
boolean z = (x || y) && (!x && y)
false
What's wrong with this code?
int i = 5;
for(int i = 5; i>=0; i--)
System.out.println(i)
System.out.println(i), missing ;
int [] array = {1, 2, 4};
for(int i = 0; i < array.length; i++)
for(int j: array)
System.out.println(j);
1
2
4
1
2
4
1
2
4
If this prints 1, what type is y?
int x = 3
___ y = x / 2;
System.out.println(y);
int
The class Character takes one integer as the health parameter. How do I create an instance of Character called steve with 100 health?
Which library can we use to create a User Interface (draw pictures)
the processing library
or
processing.core.PApplet
What is missing?
switch(choice) {
case1: System.out.println("You picked Warrior!");
case2:System.out.println("You picked Rogue!");
default:System.out.println("That wasn't an option.");
}
break; in all cases
String name = "Jeff";
String height = "56";
System.out.print("Hello my name is " + name);
System.out.print(" and I am \n" + "inches tall");
Hello my name is Jeff and I am
inches tall
What is the difference between a float and a double?
They are different sizes
How do I create a public subclass of Car called Truck?
public class Truck extends Car
How do you write the main method?
public static void main(String [] args)
I want to catch an input mismatch exception, fill in the blanks:
___ {
System.out.println("Enter the amount:");
userMoney = input.nextFloat();}
____(InputMismatchException e){
input.nextLine();
System.out.println("That's not a number. ");
userMoney = 0;}
try
catch