import javax.swing.JOptionPane; public class Mileage { public static void main(String[] args) { String inputString; double miles; double gallons; double mpg; inputString= JOptionPane.showInputDialog("This program will calculate mileage"); miles =Double.parseDouble(inputString); inputString= JOptionPane.showInputDialog("Enter amount of miles driven:"); gallons =Double.parseDouble(inputString); mpg= (miles/gallons); JOptionPane.showMessageDialog(null, "Miles per gallon: "+ mpg); System.exit(0); } } hi, I will like to know how can I display the result "mpg", but with 2 decimals? What or how should I add to my code? Also how would you explain your addition in pseudo-code?
import javax.swing.JOptionPane;
public class Mileage
{
public static void main(String[] args)
{
String inputString;
double miles;
double gallons;
double mpg;
inputString= JOptionPane.showInputDialog("This
miles =Double.parseDouble(inputString);
inputString= JOptionPane.showInputDialog("Enter amount of miles driven:");
gallons =Double.parseDouble(inputString);
mpg= (miles/gallons);
JOptionPane.showMessageDialog(null, "Miles per gallon: "+ mpg);
System.exit(0);
}
}
hi, I will like to know how can I display the result "mpg", but with 2 decimals? What or how should I add to my code? Also how would you explain your addition in pseudo-code?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images