Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package softuniada;
  2.  
  3. import java.util.*;
  4.  
  5. public class Pr01Digitivision {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int firstInt =  Integer.parseInt(scanner.nextLine());
  10.         int secondInt = Integer.parseInt(scanner.nextLine());
  11.         int thirdInt =  Integer.parseInt(scanner.nextLine());
  12.  
  13.         int sum = sum(firstInt, secondInt, thirdInt);
  14.  
  15.         if (firstInt == 0 && secondInt == 0 && thirdInt == 0) {
  16.             System.out.println("No digitivision possible!");
  17.             return;
  18.         }
  19.  
  20.         boolean hasDigitivision = false;
  21.  
  22.         for (int i = 0; i < 6; i++) {
  23.             int currentNumber = Integer.parseInt("" + firstInt + secondInt + thirdInt);
  24.  
  25.             if (String.valueOf(currentNumber).startsWith("0")) {
  26.                 continue;
  27.             }
  28.  
  29.             if (currentNumber % sum == 0) {
  30.                 hasDigitivision = true;
  31.                 break;
  32.             }
  33.  
  34.             int temp = firstInt;
  35.             firstInt = secondInt;
  36.             secondInt = thirdInt;
  37.             thirdInt = temp;
  38.         }
  39.  
  40.         if (hasDigitivision) {
  41.             System.out.println("Digitivision successful!");
  42.         } else {
  43.             System.out.println("No digitivision possible!");
  44.         }
  45.  
  46.     }
  47.  
  48.     private static int sum(int firstInt, int secondInt, int thirdInt) {
  49.         return firstInt + secondInt + thirdInt;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement