Last active
December 9, 2017 16:29
-
-
Save Dogacel/01333197f60ab33c51689a389b2e8db5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class ArrayRepeatProblem { | |
public static void print(int i) {System.out.println(i);} | |
public static void print(String s) {System.out.println(s);} | |
public static void main(String[] args) { | |
Random rn = new Random(); | |
final int ARR_SIZE = 10; | |
final int NUM_MAX = 10; | |
int[] arr = new int[ARR_SIZE]; | |
for (int i = 0 ; i < ARR_SIZE ; i++) { | |
arr[i] = rn.nextInt(NUM_MAX); | |
} | |
if (NUM_MAX <= ARR_SIZE) { | |
for (int i = 0 ; i < ARR_SIZE ; i++) { | |
arr[arr[i] % NUM_MAX] += NUM_MAX; | |
} | |
int max = arr[0] / NUM_MAX; | |
for (int i = 0 ; i < ARR_SIZE ; i++) { | |
if (arr[i] / NUM_MAX > max) | |
max = arr[i] / NUM_MAX; | |
} | |
for (int i = 0 ; i < ARR_SIZE ; i++) { | |
if (arr[i] / NUM_MAX == max) | |
print(i % NUM_MAX + " is repeating " + max + " times."); | |
} | |
print("Array : "); | |
for (int j = 0 ; j < ARR_SIZE ; j++) { | |
System.out.print(arr[j] % NUM_MAX + " "); | |
} | |
} else { | |
print("Ups, I dont know how to solve it xd"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment