Question

In: Computer Science

Write a program to calculate the area and circumference of a cuboid. Use printf to display...

Write a program to calculate the area and circumference of a cuboid.

Use printf to display 2 digits after decimal point in all the results

Program should be in java language.

Solutions

Expert Solution

Code

import java.util.*;
import java.lang.*;
import java.io.*;
class T
{
   public static void main (String[] args) throws java.lang.Exception
   {
       Scanner in= new Scanner(System.in);
       float l,b,h;
       System.out.println( "Enter values of length");
       l=in.nextFloat(); //input length
       System.out.println( "Enter values of breadth ");
       b=in.nextFloat(); //input bradth
       System.out.println( "Enter values of height");
       h=in.nextFloat(); //input height
       float A,C;
       A=2*(l*b +b*h + h*l); //calculate surface area
       C=4*(l+b+h); //calculate circumference
       System.out.printf("Area of cuboid is %.2f \n", A);
       System.out.printf("Circumference of cuboid is %.2f \n", C);
   }
}

Terminal work


Related Solutions

Write a program that calculates the area and circumference of a circle. It should ask the...
Write a program that calculates the area and circumference of a circle. It should ask the user first to enter the number of circles n, then reads the radius of each circle and stores it in an array. The program then finds the area and the circumference, as in the following equations, and prints them in a tabular format as shown in the sample output. Area = πr2 , Circumference = 2πr, π = 3.14159 Sample Output: Enter the number...
Write a program to use Math methods to calculate and display the followings: Prompts the user...
Write a program to use Math methods to calculate and display the followings: Prompts the user to enter an angle, in degrees, and then display the angle in radians and the Sine of the angle. Prompts the user to enter a positive integer and calculates the square root of the number. Computational thinking: Your program must check if it is a positive number. If a negative number is entered, it must ask for another number until the positive number is...
Please write this program in C++ Write a program that           - a user-defined class Cuboid...
Please write this program in C++ Write a program that           - a user-defined class Cuboid which has the following elements:                    - default constructor (has no parameters)                    - constructor that has 3 parameters (height, length, width)                    - data members                              - height, length, width                    - member functions                              - to set the value of each of the data members - 3 functions                              - to get the value of each of the data members - 3...
Write a program that will calculate and display the cost of a gasoline purchase based on...
Write a program that will calculate and display the cost of a gasoline purchase based on the brand of gasoline, the octane rating and the amount purchased. Your program should first display a menu prompting the user for the brand of gasoline.  Next prompt the user for the amount of gasoline in liters. Finally, your program should calculate and display the cost of the gasoline purchase using the formula below. Cost of Discount Gasoline = ($2.49 - (100 - Octane Rating)...
Write the program in Java (with a graphical user interface) and have it calculate and display...
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. You need to include Calculate, Reset, and Exit buttons on your GUI. Please insert comments in the program to document the program. Allow the user to enter...
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
Write a 'C' program to calculate the surface area of the cone and by using that,...
Write a 'C' program to calculate the surface area of the cone and by using that, also calculate the volume of the cone and print the values as surface area of the cone and volume of the cone. where as: surface area of the cone = πr2 (r is the radius of the surface) volume of the cone = (1/3)πr2h (h is the height of the cone)
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
please write it in printf and scanf please Please write it in c# program please and...
please write it in printf and scanf please Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches. Your function will convert the weight and height into Body Mass...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT