Page 86 - CA_Blue( J )_Class10
P. 86
14 System.out.print("Enter radius of a sphere in cm : ");
15 r=sc.nextDouble();
16 vs=4.0/3.0 * 3.14 * r * r * r;
17 System.out.println("Volume of a sphere : "+vs + " cu cm ");
18 System.out.println("-----------------------");
19 System.out.print("Enter length of a cuboid in cm : ");
20 l=sc.nextInt();
21 System.out.print("Enter breadth of a cuboid in cm : ");
22 b=sc.nextInt();
23 System.out.print("Enter height of a cuboid in cm : ");
24 h=sc.nextInt();
25 vcd=l * b * h;
26 System.out.println("Volume of a cuboid : "+vcd + " cu cm ");
27 System.out.println("-----------------------");
28 }
29 }
Hint:
Volume of a cube (vc) = s * s * s where s is a side of 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
You will get the following output:
5.5 USING InputStreamReader CLASS
Similar to the Scanner class, the InputStreamReader class is also used to take the input from the user during the execution
of the program. It takes input in the form of bytes and converts it into characters. To use the InputStreamReader class,
we need another class called BufferedReader. The BufferedReader class allows us to read data line by line. To utilize
the InputStreamReader class we need to import a package called java.io as follows:
import java.io.*;
//Used for including the package
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
//Used to create the object
8484 Touchpad Computer Applications-X

