Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class E02goingHome {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double boys = 5;
- double km = Double.parseDouble(scanner.nextLine()); // 120
- double litreFuel = Double.parseDouble(scanner.nextLine()); // 5
- double priceFuel = Double.parseDouble(scanner.nextLine()); //1.2
- double budget = Double.parseDouble(scanner.nextLine());//4
- double fuelPer100km = (km * litreFuel) / 100;
- double moneyForFuel = fuelPer100km * priceFuel;
- if (budget >= moneyForFuel) {
- System.out.printf("You can go home. %.2f money left.", budget - moneyForFuel);
- } else {
- double eachPlayer = budget / boys;
- System.out.printf("Sorry, you cannot go home. Each will receive %.2f money.",eachPlayer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment