Loading...

Java Numbers

int count = 40; stores two digits as one whole number, and System.out.println(count) writes 40. The screen is one line. The 4 is not a count of letters. The 0 is not a second number sitting beside it.

The digits you write are one number

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 plant if that line is still there. Delete plant.length, delete charAt, and delete every line that asks a question after a dot. Delete any import line, any reader line, and any nextLine line. The file you keep has no import, no Scanner, no nextLine, no plant, and no dot. An unused import does not by itself make javac fail, and it does not write 40 either. The digits are written only by the writing line that uses the name.

Inside main, the storing line is int count = 40;. int is the kind word. It says this name holds a whole number. count is the name, and it starts with a small c. The = sign stores the digits. The digits are 4, then 0, with nothing between them: no space, no comma, no point, and no quotes. The semicolon ends the line. This line stores the number. It does not write the screen. Storing is not writing. The screen stays blank through this line. The two digits are one number, forty written as 40, not the word forty, and not a 4 followed later by a separate 0.

The 4 on the letter-count page was an answer. plant.length() looked at leaf and the writing line showed 4, while the letters stayed leaf. That 4 was not typed as digits on a storing line. This page leaves that question. There is no plant to count. The 4 in 40 is a digit you typed, and the 0 next to it is the other digit of the same number. If the screen shows leaf, or leaf and then 4, the old lines are still in the file. Delete them until the only stored value is 40.

The writing line is the bare name: System.out.println(count);. No quotes, and no dot. Java reads the name count, writes the whole number that name holds, and ends the line. For the file you keep, that number is 40. The letters of the name, c, o, u, n, t, are not on the screen. int is not on the screen. System is not on the screen. The semicolon is not on the screen. The digits 4 and 0 are on the screen, as one line, 40. 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, count. One whole number, 40, two digits, no quotes, no point, no space between the digits, and no minus mark. One writing line, and that line uses the bare name.

the file you keep

java
public class Mint {
    public static void main(String[] args) {
        int count = 40;
        System.out.println(count);
    }
}

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. There is no String plant line in the file you keep. int count = 40; stores the two digits. It writes nothing. System.out.println(count); writes 40 and ends the line. One line on the screen. No quotes. No second line.

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. Two digits with no space between them do not make javac write a line, and they do 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 40. It does not wait for you to type. The digits were already in the file. If java Mint waits, nextLine is still in the file. Delete that line and keep int count = 40; and the one writing line. The program finishes after the writing line.

The screen shows 40. One line. No quotes. If the screen shows count, the writing line has quotes around the name: System.out.println("count");. Those quotes mark the letters c, o, u, n, t, so the stored 40 is not written. If the screen shows 4, the storing line is int count = 4;, one digit, or the file is still the letter-count page and the writing line is plant.length(). The file you keep has 40, two digits. If the screen shows 4 and then 0 on the next line, there are two writing lines, or two numbers. The file you keep has one writing line and one number. If the screen shows 400, an extra 0 is in the storing line. If the screen shows leaf, plant is still in the file. If the screen shows mint, you are still on an older file. If the screen shows forty, the writing line has the word forty between quotes. The file you keep writes digits, not that word. You do not reinstall Java for a screen that shows the wrong line.

A space between the digits is not one number. int count = 4 0; has a gap between 4 and 0. javac writes an error. It does not stay quiet. There is no screen to read, because you do not type java Mint while javac is writing an error. You do not need the exact words of that error. Delete the gap so the line is int count = 40; again. A comma is not a thousands mark on this page. int count = 4,000; is not the number 4000. javac writes an error. The file you keep has no comma. A point is still not a whole number for int. int count = 40.0; makes javac write an error, the same kind of mismatch as a point in a smaller number. The file you keep has 40, with no point and no digit after a point.

Quotes around the digits are letters, not the whole number. int count = "40"; asks an int name to hold two digit-letters. javac writes an error. It does not turn those letters into the number 40. Delete the quotes if the kind word is int. System.out.println("40"); with no int line at all would write 40 as well, because the quotes hold the characters 4 and 0. The screen can look the same. The file does not. The file you keep has int, and it has 40 with no quotes. When you judge this page, look for the kind word and look for the absence of quotes. Do not judge the kind from the screen alone.

The name has to exist before a line uses it. If System.out.println(count); is written above int count = 40;, javac writes an error. The writing line names count before count exists. Move the storing line above the writing line. This is the same order as the earlier whole-number page and as plant on the letter pages. The file you keep already has that order. Do not write int a second time for the same name. int count = 40; placed under a line that already created count is a different error. javac writes an error and does not stay quiet. The name is created once. The file you keep has one storing line.

int count = forty; treats forty as a name. This file does not have a name forty. javac writes an error. The number is the digits 40, not the word. Put the digits back. int count; with no = 40, followed by the writing line, also makes javac write an error. The name would exist as a kind, and it would hold no number yet. Put = 40 on the creating line, the way the file you keep has it.

A minus mark belongs to the digits

A mark written against the digits is part of that one number. The mark is the character - with no space required between it and the first digit. int count = -4; stores one whole number. There is no second number on the line. This page does not take 4 away from another number. There is no plus mark and no second storing of a number to combine with this one. The writing line is still System.out.println(count);. The screen shows -4. One line. The mark is on the screen, tight against the digit. The name count is not on the screen.

This is the second file. It is not the file you keep. The file you keep stores 40, with no minus mark, and its screen is 40. Save this second file as Mint.java when you want to see the mark, then put int count = 40; back.

a minus mark against one digit

java
public class Mint {
    public static void main(String[] args) {
        int count = -4;
        System.out.println(count);
    }
}

Type javac Mint.java. The file is fine, so javac writes no line. A minus mark against a digit does not make javac fail. Then type java Mint. The screen shows -4. One line. No quotes. If the screen shows 4, the mark is missing from the storing line. If the screen shows 40, you are still on the file you keep, which is the right file to return to, but it is not this check. If the screen shows -40, the storing line has the mark and both digits. That is one number too, the mark plus 40, and it is not the second file. The second file is -4 only. A space between the mark and the digit, int count = - 4;, is still that same one number. javac stays quiet, and the screen is still -4, with the mark against the digit. The space in the file is not a space on the screen, and it is not a second number. The file you keep does not use the mark. After you have seen -4, put the kept file back: int count = 40; and one System.out.println(count);.

A zero written first is a different number

A 0 written before the other digits is not "the same digits with a spare 0." int count = 040; is a line javac accepts, so javac writes no line. Then java Mint writes 32. The screen is not 40, and it is not 040. Java reads a whole number that starts with 0 in groups of eight, not in the tens you use for 40. The 4 in 040 is four eights, which is 32, and the last 0 adds nothing. You do not have to do that regrouping on paper each time. The useful fact is the screen: 32, not 40. Delete the front 0 so the storing line is int count = 40; again before you leave the page. Do not leave 040 in the file you keep.

A lone 0 is the number zero, and it is allowed. int count = 0; stores 0. System.out.println(count); writes 0. javac writes no line. java Mint writes 0 and finishes. It does not wait. A blank screen would mean the writing line is missing. The digit 0 on the screen is the number you stored, not an empty line. That lone 0 is not the same as a 0 written in front of other digits. 0 starts and ends with that one digit. 40 starts with 4. 040 starts with 0 and then has more digits, and that is the line whose screen is 32.

A front 0 followed by 8 or by 9 does not fit that grouping. int count = 08; makes javac write an error. int count = 09; does the same. Those lines are not a quiet way to store eight or nine. Delete the front 0. Eight as a whole number is int count = 8;, and the screen is 8. You do not need 08 on this page. The file you keep is 40, which starts with 4, so the file you keep does not have this error. The error is only for a line that starts with 0 and then a digit that does not fit.

The lines and the screens sit together here. The file you keep is the first row. The other rows are checks. They are not extra files to leave saved.

📊 The storing line and the screen

The storing line The screen
int count = 40; 40
int count = -4; -4
int count = 0; 0
int count = 040; 32

Read the table against a run, not instead of one. For 40, javac writes no line and java Mint writes 40. For -4, javac writes no line and java Mint writes -4. For 0, javac writes no line and java Mint writes 0. For 040, javac writes no line and java Mint writes 32. After each check, put int count = 40; back. The kept screen is 40, one line, no mark, no front 0.

You can now write a whole number as digits in the file and see those digits on the screen. int count = 40; stores 40. System.out.println(count); writes 40 and ends the line. The two digits are one number, not a letter count and not two lines. int count = -4; writes -4, and the mark is part of that one number. int count = 0; writes 0. int count = 040; lets javac stay quiet and makes java Mint write 32, so a 0 in front is not the number you meant. A space or a comma between digits makes javac write an error. The next page leaves these digits. It stores a value that is not a whole number and not a line of letters.

The screen is the number you stored

The file you keep writes 40. The name on the writing line is count, and count is not on the screen. There are no quotes in that file. One println is one line. A minus mark, when you use the second file, is part of the number on that line. A 0 written first is a different number, and it does not belong in the file you keep.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
6
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 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