Advertisement
nevenailievaa

10. Profit

Mar 6th, 2024
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package ProgramingBasicsME.NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P10Profit {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int oneLev = Integer.parseInt(scanner.nextLine());
  10.         int twoLev = Integer.parseInt(scanner.nextLine());
  11.         int fiveLev = Integer.parseInt(scanner.nextLine());
  12.         int totalSum = Integer.parseInt(scanner.nextLine());
  13.  
  14.         int one = 1;
  15.         int two = 2;
  16.         int five = 5;
  17.  
  18.         for (int i = 0; i <= oneLev ; i++) {
  19.             for (int j = 0; j <= twoLev ; j++) {
  20.                 for (int k = 0; k <= fiveLev ; k++) {
  21.                     if (i * one + j * two + five * k == totalSum ){
  22.                         System.out.printf("%d * 1 lv. + %d * 2 lv. + %d * 5 lv. = %d lv.%n", i, j, k, totalSum);
  23.                     }
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement