I need help adding a new line at the end of the output string here is my Java code, and it is all correct except at the end of the output it is requiring a newline after. import java.util.Scanner; public class LabProgram { //method drivingCost definition public static double drivingCost(double drivenMiles,double milesPerGallon,double dollarsPerGallon) { double yourValue; yourValue = (drivenMiles/milesPerGallon)*dollarsPerGallon; System.out.printf("%.2f ", yourValue); return yourValue; } public static void main(String[] args) { double milesPerGallon; double dollarsPerGallon; Scanner sc = new Scanner(System.in); milesPerGallon = sc.nextDouble(); dollarsPerGallon = sc.nextDouble(); drivingCost(10, milesPerGallon, dollarsPerGallon); drivingCost(50, milesPerGallon, dollarsPerGallon); drivingCost(400, milesPerGallon, dollarsPerGallon); } }
I need help adding a new line at the end of the output string here is my Java code, and it is all correct except at the end of the output it is requiring a newline after.
import java.util.Scanner;
public class LabProgram {
//method drivingCost definition
public static double drivingCost(double drivenMiles,double milesPerGallon,double dollarsPerGallon)
{
double yourValue;
yourValue = (drivenMiles/milesPerGallon)*dollarsPerGallon;
System.out.printf("%.2f ", yourValue);
return yourValue;
}
public static void main(String[] args) {
double milesPerGallon;
double dollarsPerGallon;
Scanner sc = new Scanner(System.in);
milesPerGallon = sc.nextDouble();
dollarsPerGallon = sc.nextDouble();
drivingCost(10, milesPerGallon, dollarsPerGallon);
drivingCost(50, milesPerGallon, dollarsPerGallon);
drivingCost(400, milesPerGallon, dollarsPerGallon);
}
}
Step by step
Solved in 2 steps with 2 images