Page 125 - ComputerScience_Class_11
P. 125
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 double si,p,r,t;
8 System.out.print("Enter the principal amount: ");
9 p=sc.nextDouble();
10 System.out.print("Enter the rate: ");
11 r=sc.nextDouble();
12 System.out.print("Enter the number of years: ");
13 t=sc.nextDouble();
14 si=(p*r*t)/100.0;
15 System.out.println("Simple Interest: "+si);
16 }
17 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Enter the principal amount: 30000
Enter the rate: 5
Enter the number of years: 4
Simple Interest: 6000.0
Write a program to find the volume of a cube, a sphere and a cuboid by accepting the required
Program 2
values from the user using Scanner class.
Hint:
Volume of a cube (vc) = s * s * s where s is a side of the cube
Volume of a sphere (vs) = 4 / 3 * π * r * r * r where π = 3.14 or 22 / 7 and r is a radius of sphere
Volume of a cuboid (vcd) = l * b * h
1 import java.util.*;
2 class scanner
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 int s,l,b,h,vc,vcd;
8 double r,vs;
Objects 123

