Write Java code to output remainingGas and totalMileage using System.out.println
Check the final answer first, then review the worked steps.
Answer
System.out.println("Remaining gallons of gas: " + remainingGas); System.out.println("Total mileage: " + totalMileage);
Work
System.out.println("Remaining gallons of gas: " + remainingGas);
System.out.println("Total mileage: " + totalMileage);
Step-by-step solution
- Use System.out.println to print the required strings and variables.
- Concatenate the string literal with the variable name using the + operator.
- Ensure the output matches the exact format requested: "Remaining gallons of gas: " and "Total mileage: ".