| 1. |
Write a program to input length breadth and height of cubes and calculate it's volume |
|
Answer» Program in JAVA code: import java.util.*; //importing util package to get the scanner class,can also have import.java.scanner public class Volume{ public static void main(String []args){ Scanner s = new Scanner(System.in); //creating the scanner to allow INPUT of data System.out.println("Please enter the unit(cm,m.mm,etc): "); String u=s.next(); //assigning the unit to the VARIABLE u System.out.println("Please enter the length: "); DOUBLE l=s.nextDouble(); //assigning the lenght to the variable l System.out.println("Please enter the breadth: "); double b=s.nextDouble(); //assigning the breadth to the variable b System.out.println("Please enter the height: "); double h=s.nextDouble(); //assigning the height to the variable h double vol=l*b*h; //calculating the volume which is lenght by breadth by height(LxBxH) and assigning it to the variable vol System.out.println("The volume is: "+vol+" "+u+" squared"); //printing the volume } } //you can copy and paste the code into an online java compiler to make changes etc. Hope i was a GOOD help! |
|