1 display values

how to display number values

this tutorial shows how to display number values and presents a simple programming task to complete

program requirements

code a simple program to output values like 123 and 12.3

learning-point

code
a number value like 123456 does not need speech marks when used in code
neither does a number like 123.456

introducing the code

here is the new code that will be featured
1 System.out.println(123456);
2 System.out.println(123.456);
understanding the code
on line 1 the println command is used again but this time using a number
notice the number is placed within the brackets but there are no speech marks
this number is a whole number, there is no fraction or decimal part
on line 2 the println command is used again, this time using a number containing a decimal point
this number is a real number, there is a fraction or decimal part
The code above will produce this output in the console
123456
123.456
The values are displayed as expected.

worth knowing about displaying numbers


Be careful with numbers and with speech marks, otherwise you may get unexpected results! Here are some examples with explanations.
1 System.out.println(123);
2 System.out.println("123");
3 System.out.println(0123);
4 System.out.println("0123");
5 System.out.println(1+1);
6 System.out.println("1+1");
7 System.out.println("1" + "1");
would output ..
123
123
83
0123
2
1+1
11
.. because
as we now know this is the way to display the number 123, one hundred and twenty three
this looks the same but it is the text 123
What! Well in java a leading 0 means that the remaining digits (123) are in
This code displays the text 0123 (useful for phone numbers)
Since there are no speech marks, java calculates the result value of the arithmetic expression
There are speech marks and so java displays exactly the text within.
How come? Well in this case there are two “1” text characters joined (concatenated) together to give the text value 11. Not the number eleven. More about concatenation later.

develop the code

Now that we have been introduced to println, let’s go on to prepare and run some code! There are some notes to read below before you open the project in
read the user interface design below to get an idea of what the program will produce.

user interface design

the final display should look like this
Hey Duke, what mammal has the most teeth?
The Giant Armadillo has 74 teeth.

Hey Duke, what is the value of the number called pi?
The value of pi is 3.14
you can compare the finished program with this sample
Using the project frame
The are 3 files in the project click the document icon📄 in repl (frame) to toggle the file list. Click a file to view the contents.
is the program file you will edit and run
README contains a guide to completing the work
CODECLIP has some sample code that you can copy and paste

It is best to open the code frame in repl, preferably in a new browser window and arrange this window alongside the repl window
right click the “open in repl” link at the top right of the project frame below
if you have a repl account you can fork the project to store your own copy

project frame

Loading…

Investigate and Make

credit wikipedia: Tony Webster from San Francisco, California - Las Vegas High Roller
This is the world’s biggest ferris wheel, the High Roller in Las Vegas!
It has a diameter of 158 metres. What is size is the circumference?
The diameter is the distance from the top of the wheel to the bottom.
The circumference is the distance around the outside of the wheel.
To calculate the circumference you can multiply the diameter by value of the number pi.

coding plan
display (diameter x 3.14)
Complete the “Investigate and Make” section of the code project.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.