write a program that accepts as input the mass (in grams) and density (in grams per cubic centimeters), and ooutputs the volume of the object using the formula: density = mass / volume.
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int mass=0;
int density=0;
int volume=0;
System.out.println("Please provide value of the mass in grams and press Enter: ");
mass=input.nextInt();
System.out.println("Please provide value of the density (in grams per cubic centimeters) and press Enter: ");
density=input.nextInt();
volume=mass/density;
System.out.println("The volume is: "+volume);
input.close();
}
}
Comments
Leave a comment