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

OOP Lab 1 Practice Problems Java Basics

The document contains a series of programming practice problems for Java, focusing on basic concepts such as output display, user input, mathematical calculations, and conditional statements. Each problem requires writing a program to perform specific tasks, such as displaying messages, calculating areas, converting units, and checking conditions. The problems are designed to enhance programming skills and understanding of Java syntax and logic.
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)
4 views

OOP Lab 1 Practice Problems Java Basics

The document contains a series of programming practice problems for Java, focusing on basic concepts such as output display, user input, mathematical calculations, and conditional statements. Each problem requires writing a program to perform specific tasks, such as displaying messages, calculating areas, converting units, and checking conditions. The problems are designed to enhance programming skills and understanding of Java syntax and logic.
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
You are on page 1/ 2

Practice problems (Lab 1):

01: Write a program that displays Welcome to Java, Welcome to Computer Science, and
Programming is fun at three different lines.

02: Write a program that displays Welcome to Java five times in five lines.

03: Write a program that displays the following table.


a a2 a3
1 1 1
2 4 8
3 9 27

04: Write a program that displays the result of,

05: Write a program that displays the area and perimeter of a circle that has a radius of 5.5 using the
following formula:
perimeter = 2 * π * radius
area = π * radius * radius

06: Change the program in the previous problem (05) in such a way so that the user enters the value of
the radius of the circle. Now compute the perimeter and area.

07: Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. Write a program that displays
the average speed in miles per hour. (Note that 1 mile is 1.6 kilometers.)

08: Change the program in the previous problem (07) in such a way so that the user gives three values:
distance the runner completed in km, minutes and seconds spent during the run. Now compute the
average speed in miles per hour.

09: Write a program that reads a Celsius degree in a double value from the console, then converts it to
Fahrenheit and displays the result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32

10: Write a program that reads an integer from the console and determines whether the given number is
divisible by either 2 or 3 (but not both). Then the program should print TRUE, otherwise, the program
should print FALSE.

11: Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number
of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample run:
12: The two roots of a quadratic equation ax2+ bx + c = 0 can be obtained using the following formula:

b2- 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real
roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots. Write a
Java program that prompts the user to enter values for a, b, and c and displays the result based on the
discriminant. If the discriminant is positive, display two roots. If the discriminant is 0, display one root.
Otherwise, display “The equation has no real roots”.

Note that you can use Math.pow(x, 0.5) to compute the square root of x..

13: Write a Java program that prompts the user to enter the exchange rate from currency in U.S. dollars
(USD) to Bangladeshi Taka (BDT). Prompt the user to enter 0 to convert from USD to BDT and 1 to
convert from BDT to USD.
Then, prompt the user to enter the amount in USD or in BDT to convert it to BDT or USD, respectively.
(Bonus [not for class test]: Use appropriate JOptionPane dialog boxes to read inputs and write outputs.)

14. Write a Java program that prompts the user to enter the center (p,q) and the radius (r) of a circle.
Then, prompts the user to enter a point (x, y) and checks whether the point is within the circle centered
at (p, q) with radius r.
For example, (4, 5) is inside the circle centered at (0,0) with radius 10 and (9, 9) is outside the circle, as
shown in the following figure.

You might also like