I have java.lang.OutOfMemoryError memory overflow issue. Hello, I have java.lang.OutOfMemoryError memory overflow issue, I am trying to write to write java code which takes a list of number couple and show me the number which couples or doubles here is the input data set line n1: represents the number of times the data set will be entered line n2: indicates the odd number of numbers to enter the third line n3: the odd number list containing a number that does not repeat
exemple:
3 ---->represents the number of times the data set will be entered
3 ----> indicates the odd number of numbers to enter
1 1234567884 1234567884 ----> liste of number
5
4 3 5 4 3
5
1 10 8 10 1
but i execute the code I have an overflow memory error. This is the code:
import java.util.ArrayList;
import java.util.Scanner;
public class myMain {
/**
* @function initialize, fonction qui initialise les valeurs d'un tableau
* @param tab: int, length: int
* @return void
* */
public static void initialize(int[] tab, int length) {
for(int i = 0; i<length; i++) {
tab[i] = 0;
}
}
public static void main(String[] args) {
ArrayList<Integer> a_pair_list = new ArrayList<Integer>();
ArrayList<Integer> a_impair_list = new ArrayList<Integer>();
int count[] = new int[Integer.MAX_VALUE]; // 100
int tab[] = new int[100];
Scanner sc = new Scanner(System.in);
int N = Integer.parseInt(sc.nextLine());
for(int j = 0; j < N; j++) {
//on permet a l'utilisateur d'entrer des valeur séparer par des espaces
String a_num_c = sc.nextLine();
String[] list = sc.nextLine().split(" ");
initialize(tab, Integer.parseInt(a_num_c));
//on converti les chaine de nombre en entier
for(int k = 0; k < list.length; k++) {
tab[k] = Integer.parseInt(list[k]);
}
/* i : compteur, tmp : stock tmporairement la valeur
à un certain index du tableau tab[]*/
int i,tmp = 0;
initialize(count, tab.length);
for(i = 0; i < tab.length; i++){
tmp = tab[i];
count[tmp]++;
}
for(i=1; i < count.length; i++){
if(count[i] > 0 && count[i] == 1){
a_impair_list.add(i);
}else if(count[i] >= 2){
a_pair_list.add(i);
}
}
}
for(int i = 0; i < a_impair_list.size(); i++) {
System.out.println("Cas n°"+i+": "+a_impair_list.get(i));
}
}
}
int count[] = new int[Integer.MAX_VALUE]; // 100