+ 2
Could anyone write a java code to calculate the efficiency of a vehicle?
6 Respuestas
+ 26
Nihal Bhardwaj another thing, i leave a comment when and where i want it and not when and where you want it
+ 19
Hello Nihal Bhardwaj no one here likes to do the homeworks for lazy people, have a nice day 👍😉
+ 19
Nihal Bhardwaj it seems to me, you are the only one who is not able to code his own homeworks 👍😉
+ 16
Hello, 😊
Please, if you want us to help you, then show us your attempt, what you don't understand exactly, where you are struggling, it will be much easier!👍😉
• SEARCH for similar QUESTIONS or ANSWERS before posting
• Include relevant TAGS
• https://www.sololearn.com/post/75089/?ref=app
• https://code.sololearn.com/WvG0MJq2dQ6y/
+ 1
import java.util.Scanner; public class MagicNumber { public static void main(String[] args) { float AvgMPG = 0; int MilesDriven = 0; int totalTrips = 0; int GallonsUsed = 0; int totalMilesPerGallon = 0; int MilesPerGallon = 0; Scanner input = new Scanner(System.in); System.out.println("Enter Miles Driven or -1 to quit: "); MilesDriven = input.nextInt(); System.out.println("Enter Gallons used to fill tank or -1 to quit: "); GallonsUsed = input.nextInt(); while ( MilesDriven != -1) { MilesPerGallon = MilesDriven / GallonsUsed; System.out.println("Miles Per Gallon for this trip: " +MilesPerGallon); totalMilesPerGallon = MilesPerGallon + totalMilesPerGallon; totalTrips = totalTrips + 1; System.out.println("Enter Miles Driven or -1 to quit: "); MilesDriven = input.nextInt(); System.out.println("Enter Gallons used to fill tank or -1 to quit: "); GallonsUsed = input.nextInt(); } if (totalTrips != 0) { System.out.println("Number of trips taken: "+ totalTrips); AvgMPG = (float) totalMilesPerGallon / totalTrips; System
0
This was my code