Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Expression {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int age = Integer.parseInt(scanner.nextLine());
- double priceWashingMachine = Double.parseDouble(scanner.nextLine());
- int priceForDoll = Integer.parseInt(scanner.nextLine()); //6
- double moneyPresent = 10;
- double numberDolls = 0;
- double moneyFromAllPresents = 0;
- int count = 0;
- for (int i = 1; i<=age; i++){
- if (i % 2 == 0){
- moneyFromAllPresents = moneyFromAllPresents + moneyPresent;
- moneyPresent = moneyPresent +10;
- count++;
- }
- else {
- numberDolls = numberDolls +1;
- }
- }
- moneyFromAllPresents = moneyPresent - count;
- double moneyFromDolls = priceForDoll * numberDolls;
- double allMoney = moneyFromAllPresents + moneyFromDolls;
- if ( allMoney > priceWashingMachine){
- allMoney = allMoney - priceWashingMachine;
- System.out.printf("yes! %.2f",allMoney);
- }
- if ( allMoney < priceWashingMachine){
- allMoney = priceWashingMachine -allMoney;
- System.out.printf("No! + %.2f",allMoney);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement