Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SmartLili {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int age = Integer.parseInt(scanner.nextLine());
- double machinePrice = Double.parseDouble(scanner.nextLine());
- double toysPrice = Double.parseDouble(scanner.nextLine());
- double result1 = 0;
- double result2 = 0;
- double result3 = 0;
- double totalResult = 0;
- double end = 0;
- int num=0;
- int num2 =0 ;
- for (int i = 1; i <=age; i++) {
- if (i%2==0){
- num += 10;
- result1 += num;
- num2 +=1;
- result2 = result1 - num2;
- } else {
- result3 +=toysPrice;
- }
- }
- totalResult = result2 + result3;
- end = (totalResult - machinePrice);
- if (totalResult>=machinePrice){
- System.out.printf("Yes! %.2f", Math.abs(end));
- } else {
- System.out.printf("No! %.2f", Math.abs(end));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement