SHARE
TWEET

Untitled

a guest Oct 15th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     static String NotEq = "Digit capacity is not equal, try again";
  7.     static String ValidErr = "Validation: Entered value is no integer";
  8.  
  9.     static int EnterValue(String msg) {
  10.         Scanner in = new Scanner(System.in);
  11.         try {
  12.             System.out.println(msg);
  13.             return in.nextInt();
  14.         } catch (Exception ex) {
  15.             in.nextLine();
  16.             System.out.println(ValidErr);
  17.             return EnterValue(msg);
  18.         }
  19.     }
  20.  
  21.     static boolean CheckValue(int Max, int Min, int Num) {
  22.         if (Max < Num || Num < Min) {
  23.             System.out.println("Ur value is not belongs [" + Min + " ; " + Max + "]");
  24.             return false;
  25.         }
  26.         return true;
  27.     }
  28.  
  29.     static void PrintArray(String msg, int[] array) {
  30.         System.out.println(msg);
  31.         for (int i = array.length - 1; i >= 0; i--) {
  32.             if (i != array.length - 1) {
  33.                 System.out.print(", ");
  34.             }
  35.             System.out.print(array[i]);
  36.         }
  37.     }
  38.  
  39.     static int EnterCheckValue(int Max, int Min, int Num, String msg) {
  40.         Scanner in = new Scanner(System.in);
  41.         do {
  42.             Num = EnterValue(msg);
  43.         }
  44.         while (!CheckValue(Max, Min, Num));
  45.         return Num;
  46.     }
  47.  
  48.     static int CheckCapacity(int Num) {
  49.         int i = 1;
  50.         do {
  51.             Num /= 10;
  52.             i++;
  53.         } while (Num / 10 != 0);
  54.         return i;
  55.     }
  56.  
  57.     static boolean BitComparison(int Num1, int Num2) {
  58.         if (CheckCapacity(Num1) != CheckCapacity(Num2)) {
  59.             System.out.println(NotEq);
  60.             return false;
  61.         }
  62.         return true;
  63.     }
  64.  
  65.     static int[] ArraySplit(int[] Arr, int Num) {
  66.         for (int i = 0; i < Arr.length; i++) {
  67.             Arr[i] = Num % 10;
  68.             Num = Num / 10;
  69.         }
  70.         return Arr;
  71.     }
  72.  
  73.     public static void main(String[] args) {
  74.         final int MaxValue = 9999999;
  75.         final int MinValue = 100;
  76.         int FirstNum = 0;
  77.         int SecondNum = 0;
  78.         do {
  79.             FirstNum = EnterCheckValue(MaxValue, MinValue, FirstNum, "Enter first num");
  80.             SecondNum = EnterCheckValue(MaxValue, MinValue, SecondNum, "Enter second num");
  81.         } while (!BitComparison(FirstNum, SecondNum));
  82.         int[] ArrOf1 = new int[CheckCapacity(FirstNum)];
  83.         int[] ArrOf2 = new int[CheckCapacity(SecondNum)];
  84.         ArrOf1 = ArraySplit(ArrOf1, FirstNum);
  85.         ArrOf2 = ArraySplit(ArrOf2, SecondNum);
  86.         for (int i = 0; i < ArrOf1.length; i++) {
  87.             ArrOf1[i] -= ArrOf2[i];
  88.         }
  89.         PrintArray("Final array", ArrOf1);
  90.     }
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top