How can you add a new line at the the end of of the output string in Java. The output is correct but it is requiring a new line I have done the System.out.println() after the 3rd method call, but it is still wrong. Here is the code with out the print line at the end and the results showing. The second picture is with the print line and showing the what is wrong as well 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); } }
How can you add a new line at the the end of of the output string in Java. The output is correct but it is requiring a new line I have done the System.out.println() after the 3rd method call, but it is still wrong. Here is the code with out the print line at the end and the results showing. The second picture is with the print line and showing the what is wrong as well
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);
}
}
![1: Compare output a
0/2
Output is nearly correct; but whitespace differs. See highlights below. Special character legend
Input
20.0 3.1599
Your output
1.58 7.90 63.20
Expected output
1.58 7.90 63.20e
2: Compare output a
0/2
Output is nearly correct; but whitespace differs. See highlights below. Special character legend
Input
30.0 3.8999
Your output
1.30 6.50 52.00
Expected output
1.30 6.50 52.00e](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd9fa295a-90dd-4ec6-950d-22c80fce920e%2Fd03218ee-a35c-42ec-a815-405884c75034%2F5hbw7tr_processed.png&w=3840&q=75)
![1: Compare output a
0/2
Output is nearly correct; but whitespace differs. See highlights below.
Special character legend
Input
20.0 3.1599
Your output
1.58 7.90 63.20
Expected output
1.58 7.90 63.20
2: Compare output a
0/2
Output is nearly correct; but whitespace differs. See highlights below.
Special character legend
Input
30.0 3.8999
Your output
1.30 6.50 52.00
Expected output
1.30 6.50 52.00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd9fa295a-90dd-4ec6-950d-22c80fce920e%2Fd03218ee-a35c-42ec-a815-405884c75034%2F0mvs3vm_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)