Dilyana86

Untitled

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