Advertisement
_MuradPro_

Array

Apr 6th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Arr {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.         System.out.println("Please enter the array's length");
  8.         int n = in.nextInt();
  9.         int[] nums = new int[n];
  10.         for(int i = 0; i < nums.length; i++) {
  11.             System.out.println("Please enter the number");
  12.             nums[i] = in.nextInt();
  13.         }
  14.         int max =0;
  15.         for(int i = 2; i <= nums.length/2; i++) {
  16.             if(lineChecking(nums,i) == 1) {
  17.                 max = i;
  18.             }
  19.         }
  20.         if(max == 0)
  21.             System.out.println("The array is not organized at all");
  22.         else
  23.             System.out.println("The array is organized in " + max + " level");
  24.        
  25.     }
  26.    
  27.     public static int arr(int[] arr, int i, int j) {
  28.         for(i=i; i<j; i++) {
  29.             if(!(arr[i] == arr[j]))
  30.                 return 0;
  31.         }
  32.         return 1;
  33.     }
  34.    
  35.     public static int lineChecking(int[] arr, int m) {
  36.         int n = arr.length;
  37.         int j = n/m - 1;
  38.         int i = 0, count = 0;
  39.         for(int t=0; t<n/m; t++) {
  40.             count += arr(arr, i, j);
  41.             j += n/m;
  42.             i += n/m;
  43.         }
  44.         if(count == n/m)
  45.                 return 1;
  46.         return 0;
  47.     }
  48.        
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement