Order the following data types from smallest to largest:
char, boolean, double, int, String
boolean, char, int, double, String
boolean bool = 5 >7 - That code segment sets the value of bool to this
What is false?
String name = "Taylor";
System.out.println(name.substring(0,2);
Ta
When is it better to use a for loop instead of a while loop?
When you know exactly how many times you want a loop to run.
int y = (13-7) / 4;
1
This is the expression used to compare two values (non-Strings)
What is the Java API documentation used for?
It's used to see all the methods, fields and constructors for a particular class.
Set up a for loop for running through all the letters in a string called a and printing it to the screen
for(int i =0; i<a.length(); i++){
System.out.println(a.substring(0,1));
}
i=14,567;
i%=100;
What is 67?
This is the kind of statement that is usually found in between if and else statements
What are else if statements?
Math.random() generates a random number from this range
What is 0 to 1, including 0 but not 1?
What is the output?
for (int i = 12; i >= 5; i -= 3)
{
System.out.print(i + " ");
}
12 9 6
DAILY DOUBLE
This is what it's called when you change one variable type into another
When you use this kind of statement, it's usually to catch anything that didn't fit the conditions of the blocks before it
What is an else statement?
What would the fields be for the Rectangle class?
length and width
What is the output?
for (int i = 1; i < 4; i++)
{
for (int j = 0; j < i; j++)
{
System.out.print(i);
}
System.out.println();
}
1
22
333
Adding two Strings together is called this - kind of a long name for such a simple concept
What is concatenation?
This is what to use when comparing equality in Strings
What is .equals?
Describe the difference between autoboxing and unboxing in Java.
Converting an object of a wrapper type (Integer) to its corresponding primitive (int) value is called unboxing.
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this is called unboxing.
What is output by the following code?
for (int i = 1; i < 7; i++)
{
for (int y = 1; y <= 5; y++)
{
System.out.print("*");
}
System.out.println();
}
A rectangle of 6 rows with 5 stars per row