Variables · Output · Errors · Division · Scanner
Write the code, then try to compile
1. Write the code shown on the right in your editor.
2. Try to compile — what happens?
3. Fix any issues and identify the error type.
Write the code, then compile and run it
1. Write the code shown on the right in your editor.
2. Compile, 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 — observe what value you get.
3. The code compiles and runs, so no Syntax or Runtime Error. Is the result correct?
4. Identify the error type and fix it so the decimal portion is preserved.
Two ways to output text
1. Write code that prints the following in exactly this layout:
2. Hello World Java on one line.
3. end on the next line.
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 of these is a valid variable name:
myVar 2ndPlace class _temp my-var MAX_SIZE my var count2
2. For each invalid name, state which rule it breaks.
Printing special characters
1. Write code that prints: He said "Hello"
2. Then print a file path: C:\Users\Name — the backslashes must appear in the output.
3. Then use a single output statement to print two lines:
Line1
Line2
Can you use a variable without giving it a value?
1. Declare double b; without assigning a value.
2. Try to print b using System.out.println(b).
3. Compile and observe what happens.
4. Identify the error type and fix it.
int vs double — truncation and promotion
1. Declare int c = 8 / 7 and print c. What value? Why?
2. Declare double d = 8 / 7 and print d. Why not 1.142...?
3. Declare double e = 8.0 / 7 and print e. Why is this different?
4. Explain integer truncation and automatic promotion in your own words.
What happens when int meets double?
1. Declare an int and a double variable with any values.
2. Compute intVar + doubleVar * 2 and print the result.
3. Now try to store that result into an int variable — what does the compiler say?
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 a constant final double RATE = 0.15 for the rate.
3. Calculate a fee based on the amount and the rate, then print it.
4. Explain: what type is the result when an int multiplies a double?
Can you change a final variable?
1. Declare a constant final int MAX_SCORE = 100.
2. Try to reassign MAX_SCORE to a different value.
3. Compile and observe what happens.
4. Explain what final means and why this error occurs.