marmotka

Control Number _exam_19_03_2017

Apr 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package exam_17_03_19;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p06_Control_number {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int n = Integer.parseInt(scan.nextLine());
  9.         int m = Integer.parseInt(scan.nextLine());
  10.         int control = Integer.parseInt(scan.nextLine());
  11.         int sum = 0;
  12.         int loopCount = 0;
  13.  
  14.         for (int i = 1; i <= n; i++) {
  15.             for (int j = m; j >= 1; j--) {
  16.                 sum = sum + (i * 2 + j * 3);
  17.                 loopCount++;
  18.                 if (sum >= control) {
  19.                     System.out.printf("%d moves%n", loopCount);
  20.                     System.out.printf("Score: %d >= %d", sum, control);
  21.                     break;
  22.                 }
  23.             }
  24.         }
  25.         if (sum < control) {
  26.             System.out.printf("%d moves", loopCount);
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment