Java Operators
int total = 4 + 9; stores one whole number made with a plus mark between 4 and 9, and System.out.println(total) writes 13. The screen is one line. The mark itself is not on that line, and there is no second line for 4 or for 9.
A mark sits between two numbers
Open Mint.java. The file name stays Mint.java, because public class Mint is still the name of the file. This page does not rename the file, and it does not change public class Mint. Delete String[] plants if that line is still there, including the braces, leaf, mint, and every plants[0] writing line. Delete String plant = null if that line is still there. Delete plant.length and delete charAt. Delete int count if that line is still there, including 40, -4, and 040. Delete double weight if it is still there. Delete boolean ripe if it is still there. Delete any import line, any reader line, and any nextLine line. The file you keep has no import, no Scanner, no nextLine, no plants, no plant, no count, no weight, and no ripe. An unused import does not by itself make javac fail, and it does not write 13 either. The number is written only by the writing line that uses the name that holds the combined value.
Inside main, the storing line is int total = 4 + 9;. int is the kind word. It says this name holds a whole number. total is the name, and it starts with a small t. The = sign stores. On the right of = sit two whole numbers and one mark. The first number is 4. The mark is +. The second number is 9. There are no quotes around 4, and there are no quotes around 9. The semicolon ends the line. This line stores one number. It does not write the screen. Storing is not writing. The screen stays blank through this line. The two numbers are not kept as two separate names on this page. The mark does not sit on the screen by itself. The mark tells Java how to make the one number that total will hold.
A mark between two numbers is not the same work as a mark against one number. On the numbers page, int count = -4; wrote a minus mark against the digits of one number. That line had no second number to combine with. This page puts a mark between two numbers that already stand on their own. int total = 4 + 9; has a 4, then a plus mark, then a 9. The plus mark is not glued to 4 as a signed 4, and it is not glued to 9 as a signed 9. It sits in the middle and combines them. If the screen shows -4, the numbers file is still in place. Delete that line. If the screen shows leaf, the arrays file is still in place. Delete the braces and the brackets.
The writing line is the bare name: System.out.println(total);. No quotes, and no mark on that line. Java reads the name total, writes the whole number that name holds, and ends the line. For the file you keep, that number is 13. The letters of the name, t, o, t, a, l, are not on the screen. int is not on the screen. The plus mark is not on the screen. The digit 4 is not on the screen by itself. The digit 9 is not on the screen by itself. The digits 1 and 3 are on the screen, as one line, 13. Save the file.
The file you keep
Save this as Mint.java. It is the file this page keeps. One kind word, int. One name, total. One storing line that writes 4, then a plus mark, then 9, with no quotes around either number. One writing line, and that line uses the bare name. There is no plants line, no null line, and no second writing line.
public class Mint {
public static void main(String[] args) {
int total = 4 + 9;
System.out.println(total);
}
}
Read it from the top. public class Mint names the file. It does not write the screen. public static void main(String[] args) is where Java starts. The word String on that main line is still not a storing line. The brackets on that main line belong to args, and this page does not read args. int total = 4 + 9; stores one whole number. It writes nothing. System.out.println(total); writes 13 and ends the line. One line on the screen. No quotes. No second line. There is no String[] line in the file you keep, and there is no line that stores null.
What the screen shows
In the folder that contains this Mint.java, type javac Mint.java. When the file is fine, that command writes no line. A plus mark between two whole numbers does not make javac write a line, and it does not make javac fail. Then type java Mint. Do not type .java after java. The same two commands are what you type on Windows and on macOS. This page does not quote the shell prompt. The program writes 13. It does not wait for you to type. The two numbers and the mark were already in the file. If java Mint waits, nextLine is still in the file. Delete that line and keep int total = 4 + 9; and the one writing line. The program finishes after the writing line.
The screen shows 13. One line. No quotes. If the screen shows 4, the writing line may still print a different name, or the storing line may still be int total = 4; with no mark and no second number. The file you keep has both numbers and the plus mark. If the screen shows 9, the second number alone is being written, or the mark is missing. If the screen shows 4 + 9 as letters, the writing line has quotes around those characters: System.out.println("4 + 9");. Those quotes mark letters, so the combined number is not written. If the screen shows total, the writing line has quotes around the name. If the screen shows leaf, plants is still in the file. If the screen shows null, the null file is still in place. If the screen shows 40, the numbers file is still in place. You do not reinstall Java for a screen that shows the wrong line.
A screen that shows 13 does not, by itself, prove the plus mark. int total = 13; also writes 13. The screen can look the same. The file does not. The file you keep has 4, then +, then 9. When you judge this page, look for the mark between the two numbers. Do not judge the file from the screen alone.
Spaces around the mark are allowed. int total = 4+9; with no spaces still stores 13, and javac writes no line. int total = 4 + 9; with spaces still stores 13. The file you keep uses spaces around the mark, because the mark is easier to see that way. The spaces are not a second value. A missing number is not allowed. int total = 4 + ; makes javac write an error. int total = + 9; is not the file you keep. A plus mark against one number, as in int total = +9;, stores 9. That line has no second number to combine with. It is allowed, and it is not the file you keep. The file you keep has two numbers and one mark between them.
Quotes around a number turn it into letters. int total = "4" + 9; asks Java to combine letters with a whole number in a way this page does not teach. javac writes an error, or the screen is not the number 13. Delete the quotes. Both sides of the mark, on this page, are whole numbers with no quotes. System.out.println(4 + 9); with no total name at all also writes 13. The screen can look the same. The file you keep stores the combined number under a name first, then writes that name. When you judge this page, look for int total and look for the mark on the storing line.
The name has to exist before a line uses it. If System.out.println(total); is written above int total = 4 + 9;, javac writes an error. The writing line names total before total exists. Move the storing line above the writing line. Do not write int a second time for the same name. A later line can replace the number without writing int again, once total already exists: total = 4 + 9;. That form is allowed. It is not required. The file you keep creates the name and stores the combined number on one line.
Other marks write other numbers
The plus mark is not the only mark. A minus mark between two numbers takes the second away from the first. int total = 9 - 4; stores 5. This run is allowed, and it is not the file you keep. Type javac Mint.java. javac writes no line. Then type java Mint. The screen shows 5. One line. The mark on the screen is not written as a letter. Only the digit 5 is written. After you have seen 5, put the plus mark back. The file you keep writes 13.
A star mark multiplies. int total = 4 * 9; stores 36. javac writes no line. java Mint writes 36. One line. The star is the multiply mark on this page. Do not write the word times. Do not write x as a multiply mark. int total = 4 x 9; treats x as a name. This file does not have that name. javac writes an error. After you have seen 36, put 4 + 9 back.
Whole numbers drop the leftover
A slash mark divides. When both sides are whole numbers, the answer is a whole number too. The leftover part after the division is dropped. It is not rounded up. It is not kept as a point and more digits on this page.
public class Mint {
public static void main(String[] args) {
int total = 9 / 4;
System.out.println(total);
}
}
This is the second file. It is not the file you keep. Type javac Mint.java. javac writes no line. Then type java Mint. The screen shows 2. One line. It does not show 2.25. It does not show 2.0. It does not show 9 / 4 as letters. Four goes into nine two times as a whole number, and the leftover is not written on this screen. If the screen shows 13, you are still on the file you keep. Put this second file in place only when you want to see the dropped leftover. If the screen shows 0, the storing line may be int total = 4 / 9;, because four does not contain nine even once as a whole number. That line is allowed, and it is not this second file. This second file is 9 / 4, and the screen is 2.
A point on either side leaves whole-number division. int total = 9.0 / 4; is not an int storing line that this page keeps. javac writes an error when the kind word is int and the right side is not a whole-number result this page is teaching. Keep both sides as whole numbers with no point when you want the dropped leftover shown as 2. After you have seen 2, put the kept file back: int total = 4 + 9; and one System.out.println(total);.
The leftover mark
The leftover that division drops can be stored with a different mark. That mark is %. It is not the word percent. It is not a comment mark. Between two whole numbers, it stores what remains after whole-number division.
public class Mint {
public static void main(String[] args) {
int total = 10 % 3;
System.out.println(total);
}
}
This is the third file. It is not the file you keep. Type javac Mint.java. javac writes no line. Then type java Mint. The screen shows 1. One line. Three goes into ten three times as a whole number, and 1 is left. The screen does not show 3. The screen does not show 10 % 3 as letters. If the screen shows 0, both sides divide evenly, as in int total = 9 % 3;, which stores 0. That line is allowed, and it is not this third file. If the screen shows 2, you may still be on the division file. Put this third file in place only for the leftover check. After you have seen 1, put the kept file back.
📊 The mark between two numbers and the screen
| The storing line | The screen |
|---|---|
| int total = 4 + 9; | 13 |
| int total = 9 - 4; | 5 |
| int total = 4 * 9; | 36 |
| int total = 9 / 4; | 2 |
| int total = 10 % 3; | 1 |
| int total = 4; | 4 |
Read the table against a run, not instead of one. For the plus mark, javac writes no line and java Mint writes 13. For the minus mark between two numbers, the screen is 5. For the star mark, the screen is 36. For the slash mark with whole numbers, the screen is 2, and the leftover is not on that line. For the leftover mark, the screen is 1. For int total = 4; with no second number and no mark, the screen is 4, and that line is not the file you keep. After each check, put the kept file back: int total = 4 + 9; and System.out.println(total);. The kept screen is 13, one line.
Writing the mark as letters does not combine the numbers. System.out.println("4 + 9"); writes the characters 4, space, +, space, 9. The screen shows 4 + 9. That is not the number 13. javac stays quiet. The quotes are what stop the mark from working as a mark. The file you keep has no quotes around the numbers, and the writing line has no quotes around the name.
A comma is not a mark on this page. int total = 4, 9; makes javac write an error. Do not use a comma to stand between two numbers you want to combine. The marks this page keeps are +, -, *, /, and %. Comparison marks such as == belong on a later page. Logical marks such as && belong on a later page. This page does not store true or false. If the screen shows true, ripe is still in the file. Delete that line.
You can now store one whole number made with a mark between two whole numbers and write that number. int total = 4 + 9; stores 13. System.out.println(total); writes 13 and ends the line. int total = 9 / 4; writes 2, because whole numbers drop the leftover. int total = 10 % 3; writes 1, the leftover. A minus mark between two numbers is not the same as a minus mark against one number. The next page leaves these combining marks. It looks at marks that ask whether one number matches another.
The screen is the combined number
The file you keep writes 13. The name on the writing line is total, and total is not on the screen. The plus mark is in the file, and it is not on the screen. 4 and 9 are in the file, and they are not on the screen as separate lines. Whole-number division and the leftover mark are not the file you keep. Quotes around the mark write letters, not the combined number.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top