Variables · Output · Errors · Division · Scanner
Write the code, then try to compile
1. Write the code shown below in your editor.
2. Compile the code and observe what happens.
3. Fix any issues, then identify the error type.
Write the code, then compile and run it
1. Write the code shown below in your editor.
2. Compile the code, then run the program.
3. Observe what happens, identify the error type, and fix it.
It compiles and runs — but is the answer right?
1. Write code that calculates the average of 10 and 3.
2. Use only integer variables and observe the resulting value.
3. Decide whether the result is correct even though the code compiles and runs.
4. Identify the error type, then fix it so the decimal portion is preserved.
Two ways to output text
1. Print Hello World Java on one line.
2. Print end on the next line.
Hello World Java end
When do you need double quotes?
1. Print the boolean value false.
2. Print the integer 5.
3. Print the String "5".
4. Explain why false and 5 do not need double quotes.
Which names are valid?
1. Identify whether each item is a valid variable name:myVar 2ndPlace class _temp my-var MAX_SIZE my var count2
2. State which rule each invalid name breaks.
Printing special characters
1. Print He said "Hello".
2. Print the file path C:\Users\Name with the backslashes visible.
3. Use one output statement to print two lines:Line1Line2
He said "Hello" C:\Users\Name Line1 Line2
Can you use a variable without giving it a value?
1. Declare double b; without assigning a value.
2. Print b using System.out.println(b).
3. Compile the code and observe what happens.
4. Identify the error type, then fix it.
int vs double — truncation and promotion
1. Declare int c = 8 / 7, print c, and explain the value.
2. Declare double d = 8 / 7, print d, and explain why the result is not 1.142....
3. Declare double e = 8.0 / 7, print e, and explain why the result is different.
4. Explain integer truncation and automatic promotion in your own words.
What happens when int meets double?
1. Declare one int variable and one double variable with any values.
2. Compute intVar + doubleVar * 2 and print the result.
3. Store that result in an int variable and observe the compiler response.
4. Explain which type wins when int and double mix.
Combining user input with constants
1. Write a program that asks the user to enter an integer amount.
2. Use the constant final double RATE = 0.15 for the rate.
3. Calculate a fee based on the amount and rate, then print it.
4. Explain the result type when an int multiplies a double.
Can you change a final variable?
1. Declare the constant final int MAX_SCORE = 100.
2. Reassign MAX_SCORE to a different value.
3. Compile the code and observe what happens.
4. Explain what final means and why the error occurs.