0% found this document useful (0 votes)
34 views

Java Ex 01

This tutorial provides a series of programming exercises for students to complete using a text editor. It includes exercises to write simple Java programs that output names and ages, perform basic math operations like adding numbers and calculating averages, convert between units like meters and centimeters, and format numeric output. Students are asked to write code to calculate volumes, temperatures, wage bills, and format currency values with commas.

Uploaded by

Nithin Kaneshan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Java Ex 01

This tutorial provides a series of programming exercises for students to complete using a text editor. It includes exercises to write simple Java programs that output names and ages, perform basic math operations like adding numbers and calculating averages, convert between units like meters and centimeters, and format numeric output. Students are asked to write code to calculate volumes, temperatures, wage bills, and format currency values with commas.

Uploaded by

Nithin Kaneshan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tutorial 1

*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.

4. Write a program to declare a variable for each variable type, Initialize


each variable to its minimum and maximum value and print the result. Then try adding
and subtracting 1 from each respectively. Describe what happens and why.
int myInt = 2147483647;
System.out.println(myInt + 1);

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

You might also like