0% found this document useful (0 votes)
16 views2 pages

Java Programming Lab Exercises

The document outlines a series of basic Java programming exercises, including tasks for calculating products, converting temperature, displaying numbers, and performing arithmetic operations. It also covers selection statements, looping constructs, array manipulations, and string handling. Each exercise is designed to reinforce fundamental programming concepts and skills in Java.

Uploaded by

ssyuaib0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Java Programming Lab Exercises

The document outlines a series of basic Java programming exercises, including tasks for calculating products, converting temperature, displaying numbers, and performing arithmetic operations. It also covers selection statements, looping constructs, array manipulations, and string handling. Each exercise is designed to reinforce fundamental programming concepts and skills in Java.

Uploaded by

ssyuaib0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB EXERCISE BASIC JAVA PROGRAM

Basic program

1. Write a program that calculates and prints the product of three integers.

2. Write a program that converts a Fahrenheit degree to Celsius using the following
formula. Get the fahrenheit value from user.

celcius = (fahrenheit – 32) x 5 / 9

You may switch your program by declaring/receiving the celcius value and
convert to fahrenheit.

fahrenheit = celcius x 9 / 5 + 32

3. Write an application that displays the numbers 1 to 4 on the same line, with each
pair of adjacent number separated by one space. Write the application using
the following techniques:

a. Use one [Link] statement.


b. Use four [Link] statements.

4. Write an application that asks the user to enter two integers, obtains them from
the user and prints their sum, product, difference and quotient (division).

Selection

5. Write an application that asks the user to enter two integers, obtains them from
the user and displays the larger number followed by the words “is larger”. If the
numbers are equal, print “These numbers are equal”

6. Write an application that inputs three integers from the user and displays the
sum, average, product, smallest and largest of the numbers.

7. Write an application that reads two integers, determines whether the first is a
multiple of the second and print the result.

1
Looping

8. Write a Java application that uses looping to print the following table of values:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

9. Write a complete Java application to prompt the user for the double radius of a
sphere, and call method sphereVolume to calculate and display the volume of
the sphere. Use the following formula to calculate the volume:

volume = 4 / 3 x pie x radius3

You may ask user to continue calculating volume of another sphere. Use
sentinel value.

Array

10. The process of finding the largest value (i.e., the maximum of a group of values)
is used frequently in computer applications. For example, a program that
determines the winner of a sales contest would input the number of units sold
by each sales person. The sales person who sells the most units wins the
contest. Write a Java application that inputs a series of 10 integers and
determines and prints the largest integer.

11. Write a Java application that allows the user to enter up to 20 integer grades
into an array. Stop the loop by typing in ‐1. Your main method should call an
Average method that returns the average of the grades. Use the DecimalFormat
class to format the average to 2 decimal places.

String

12. Write a Java program that reads a string from the keyboard, and outputs the
string twice in a row, first all uppercase and next all lowercase. If, for instance,
the string “Hello" is given, the output will be “HELLOhello"

13. Write a Java program that reads 5 student names. Find dan display the shortest
character of the names.

You might also like