Problems: Simple Programs
Reading Time: 7 minutes
Printing Information
Write a program in Java that takes input from user his/her details and then prints it back on screen.
Enter your name: Abhimanyu
Enter your gender: M
Enter your age: 16
Enter your height: 213.36
Your name is: Abhimanyu
Your gender is: M
Your age is: 16
Your height is: 213.36
Welcome Human!Geometrical Problems
Review programs in Java to solve simple geometrical problems.
Finding Perimeter and Area
Write a program in Java that takes length L and width W of a rectangle from user and calculates the perimeter and area of the rectangle.
\[ \begin{aligned} \text{Perimeter of a rectangle} &= 2 \times (\text{length} + \text{width}) \\ \text{Area of a rectangle} &= \text{length} \times \text{width} \\ \end{aligned} \]
Enter length of rectangle: 5
Enter width of rectangle: 7
Perimeter of rectangle is: 24
Area of rectangle is: 35Finding Circumference and Area
Write a program in Java that takes radius R of a circle from user and calculates the circumference and area of the circle.
\[ \begin{aligned} \text{Circumference of a circle} &= 2 \times \pi \times \text{radius} \\ \text{Area of a circle} &= \pi \times \text{radius}^2 \\ \pi &= 3.14 \end{aligned} \]
Enter radius of circle: 5
Circumference of circle is: 31.42
Area of circle is: 78.54Finding Surface Area and Volume
Write a program in Java that takes one side S of a cube from user and calculates the volume and surface area of the cube.
\[ \begin{aligned} \text{Volume of a cube} &= \text{side} \times \text{side} \times \text{side} \\ \text{Surface area of a cube} &= 6 \times \text{side} \times \text{side} \\ \end{aligned} \]
Enter side of cube: 4
Surface area of cube is: 96
Volume of cube is: 64Percentage Problems
Review programs in Java to solve simple real-life percentage related problems.
Finding Percentage of Marks
Class teachers have a tiring task of calculating the percentage of marks obtained in science subjects for each students. To help them out, your class decides to ease their task.
Write a program in Java that takes marks obtained by a student in Biology B, Physics P, and Chemistry C, along with the total marks T of all the three subject and calculate the percentage of marks obtained in science subjects by a student.
\[ \text{Marks obtained} = \frac{\text{Marks obtained in (Biology + Physics + Chemistry)}}{\text{Total marks of science subjects}} \times 100 \]
Enter marks obtained in Biology: 80
Enter marks obtained in Chemistry: 78
Enter marks obtained in Physics: 85
Enter total marks of all subjects: 300
Marks obtained in Science subjects: 81Finding Simple Interest
One of your rich relative is in a business of giving out loans. Being in a loan business, he often has to calculate simple interest. So, you decided to ease his task of finding interest payable by clients.
Write a program in Java that takes from user a principal amount P, annual rate of interest R, and time of loan T and calculates the simple interest and total amount payable at the end of loan period.
\[ \begin{aligned} \text{Interest} &= \text{Principal} \times \text{Time} \times \frac{Rate}{100} \\ \text{Amount} &= \text{Interest} + \text{Principal} \\ \end{aligned} \]
Enter principal amount: 25000
Enter interest rate: 2.5
Enter time elapsed: 3
Interest payable: 1875
Total amount payable: 26875Finding Gain Percentage
Sneha owns a stationery shops and wants to make a certain gain on each item she sells. Help her out by writing a program for her.
Write a program in Java for her that takes the cost price CP of an item and the gain percentage GP she wants and then calculate the selling price of the item.
\[ \text{Selling price} = \text{Cost price} \times \left( 1 + \frac{\text{Gain \%}}{100} \right) \]
Enter cost price of item: 50
Enter gain percentage: 30
Selling price will be: 65SI Unit Problems
SI units is the future. Yet, people still tend to use the old-school British sytem of units instead of the new standards of units. To help people out and make remarkable change on the society, you decided to write a bunch of programs to convert older units to newer SI units.
Converting Gram to Kilogram
Write a program in Java that takes a weight G in grams from user and prints the corresponding weight in Kilogram.
Enter weight (in G): 2500
Weight (in KG) is: 2.5Converting Fahreinheit to Celsius
Write a program in Java that takes a temperature F in Fahreinheit from user and prints the corresponding temperature in Celsius.
Enter temperature (in F): 98.2
Temperature (in C) is: 36.8Converting H:M:S to Seconds
Write a program in Java that takes hours H, minutes M, and seconds S from user and prints the corresponding time in seconds.
Enter hour: 42
Enter minutes: 14
Enter seconds: 5
Total seconds: 152045