Advertisement
Spocoman

05. Salary

Aug 27th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Salary {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int salary = Integer.parseInt(scanner.nextLine());
  8.        
  9.         for (int i = 0; i < n && salary > 0; i++) {
  10.             String apps = scanner.nextLine();
  11.             if (apps.contains("Facebook")) {
  12.                 salary -= 150;
  13.             } else if (apps.contains("Instagram")) {
  14.                 salary -= 100;
  15.             } else if (apps.contains("Reddit")) {
  16.                 salary -= 50;
  17.             }
  18.         }
  19.  
  20.         if (salary <= 0) {
  21.             System.out.println("You have lost your salary.");
  22.         } else {
  23.             System.out.println(salary);
  24.         }
  25.     }
  26. }
  27.  
  28. ИЛИ:
  29.  
  30. import java.util.Scanner;
  31.  
  32. public class Salary {
  33.     public static void main(String[] args) {
  34.         Scanner scanner = new Scanner(System.in);
  35.         int n = Integer.parseInt(scanner.nextLine());
  36.         int salary = Integer.parseInt(scanner.nextLine());
  37.  
  38.         for (int i = 0; i < n && salary > 0; i++) {
  39.             String apps = scanner.nextLine();
  40.             salary -= apps.contains("Facebook") ? 150 : apps.contains("Instagram") ? 100 : apps.contains("Reddit") ? 50 : 0;
  41.         }
  42.  
  43.         System.out.println(salary > 0 ? salary :"You have lost your salary.");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement