Advertisement
veronikaaa86

Control Num

Oct 30th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package Exam19March2017Evening;
  2.  
  3.         import java.util.Scanner;
  4.  
  5. public class P06_ControlNumber {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int N = Integer.parseInt(scanner.nextLine());
  10.         int M = Integer.parseInt(scanner.nextLine());
  11.         int control = Integer.parseInt(scanner.nextLine());
  12.  
  13.         boolean isReached = true;
  14.         int counter = 0;
  15.         int sum = 0;
  16.         for (int i = 1; i <= N; i++) {
  17.             for (int j = M; j >= 1; j--) {
  18.                 sum = sum + (i*2) + (j*3);
  19.                 counter++;
  20.                 if (sum>=control){
  21.                     break;
  22.                 }
  23.             }
  24.             if (sum>=control){
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         if (sum>=control){
  30.             System.out.println(counter + " moves");
  31.             System.out.printf("Score: %d >= %d", sum, control);
  32.         } else {
  33.             System.out.println(counter + " moves");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement