Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Arr {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter the array's length");
- int n = in.nextInt();
- int[] nums = new int[n];
- for(int i = 0; i < nums.length; i++) {
- System.out.println("Please enter the number");
- nums[i] = in.nextInt();
- }
- int max =0;
- for(int i = 2; i <= nums.length/2; i++) {
- if(lineChecking(nums,i) == 1) {
- max = i;
- }
- }
- if(max == 0)
- System.out.println("The array is not organized at all");
- else
- System.out.println("The array is organized in " + max + " level");
- }
- public static int arr(int[] arr, int i, int j) {
- for(i=i; i<j; i++) {
- if(!(arr[i] == arr[j]))
- return 0;
- }
- return 1;
- }
- public static int lineChecking(int[] arr, int m) {
- int n = arr.length;
- int j = n/m - 1;
- int i = 0, count = 0;
- for(int t=0; t<n/m; t++) {
- count += arr(arr, i, j);
- j += n/m;
- i += n/m;
- }
- if(count == n/m)
- return 1;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement