Java Ex 01
Java Ex 01
*You are required to use a text-editor for this tutorial. NO IDEs are allowed.
1. Which of these are not allowed as variable names?
1. The cost
2. 2Much
3. Much2
4. *star
5. My999Var
2. Write a Java program called “MyFirstJava”. implement the man method. print your
name and age to the console. Compile and run the program on command prompt.
3. Write a program (use any name you like) to put zero in a variable called runningTotal.
Then, write separate instructions to add the following numbers onto what is in the
variable,
adding one number at a time 5, 8, 2, 3. Compile and run the program.
5. Write a program that reads in three exam marks and calculates their mean (average) and
outputs the result.
6. Write a program to calculate the volume of a box given its three dimensions. (length,
height, width)
7. Write a program that changes metres into centimetres. When the program is running, it
should allow you to enter the number in metres and then the program should print out
the number in centimetres. (Use appropriate Variable types according to your
understanding)
8. Write a program that will read in a Centigrade temperature and then display the
Fahrenheit temperature using the formula.
F = (9.0/5)*C + 32
Software Development II
9. Assume the variable “v1”references a double value. Write a statement that displays the
value rounded to two decimal points.
10. A company employs Manual, Skilled and Management people. Manual earn £500 per
week, Skilled earn £700 per week and Management earn £800 per week.
Write a program that reads how many manual, skilled and management people there
are in a company and then print out the wage bill.
The program should additionally print out the approximate tax to pay which is 20% of
the total wage bill.
Challenge Question
Assume the following statement has been executed:
number = 1234567.456
Write a Java statement that displays the value referenced by the number variable
formatted as 1,234,567.5
Software Development II