Untitled
unknown
plain_text
3 years ago
910 B
34
Indexable
import java.util.Scanner;
public class Exercise4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int age = Integer.parseInt(scanner.nextLine());
double washingMachine = Double.parseDouble(scanner.nextLine());
int toyPrice = Integer.parseInt(scanner.nextLine());
int birthdayMoney = 0;
int toys = 0;
for (int i = 1; i <= age; i++) {
if (i % 2 > 0) {
toys++;
} else {
birthdayMoney+= i * 5 - 1;
}
}
int totalMoney = toys * toyPrice + birthdayMoney;
double result = Math.abs(totalMoney - washingMachine);
if (totalMoney >= washingMachine) {
System.out.printf("Yes! %.2f", result);
} else {
System.out.printf("No! %.2f", result);
}
}
}Editor is loading...