import javax.swing.JOp tionPane;
public class MilesPerGallon
{
public static void main(String[] args)
{
String miles;
String gallons;
double MPG;
double miles1, gallons1;
miles=JOptionPa ne.showInputDia log("Enter the number of miles driven : ");
gallons=JOption Pane.showInputD ialog("Enter gallons of gas used : ");
miles1=Double.p arseDouble(mile s);
gallons1=Double .parseDouble(ga llons);
MPG = miles1 / gallons1;
JOptionPane.sho wMessageDialog( null,"Your Car's Mileage is : " + MPG + "\n");
System.exit(0);
}
}
this returns me a dialog where in I enter 400 then another dialog where in i enter 3.. the result is 133.33333333333 4 how do i restrict the result to 2 decimal places...
public class MilesPerGallon
{
public static void main(String[] args)
{
String miles;
String gallons;
double MPG;
double miles1, gallons1;
miles=JOptionPa ne.showInputDia log("Enter the number of miles driven : ");
gallons=JOption Pane.showInputD ialog("Enter gallons of gas used : ");
miles1=Double.p arseDouble(mile s);
gallons1=Double .parseDouble(ga llons);
MPG = miles1 / gallons1;
JOptionPane.sho wMessageDialog( null,"Your Car's Mileage is : " + MPG + "\n");
System.exit(0);
}
}
this returns me a dialog where in I enter 400 then another dialog where in i enter 3.. the result is 133.33333333333 4 how do i restrict the result to 2 decimal places...
Comment