Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

By trial and error, discover what the largest value of x can be in the following

ID: 648356 • Letter: B

Question

By trial and error, discover what the largest value of x can be in the following program so that it still compiles and runs without error:main(){
int array[x][x];
array[0][0] = 0;
}

Print this value of x at the start of your submission. Then use malloc to create a 5000 by 5000 square array. Fill this array with random numbers in the range [0, 6]. Iterate through the array again, counting the number of times each value appeared.

Sample session (note: for the purpose of this sample, the value of x is incorrect. You should discover this value on your own.)
> ./a.out
x = 12
there are 3570129 0s
there are 3570751 1s
there are 3571904 2s
there are 3573195 3s
there are 3571223 4s
there are 3568653 5s
there are 3574145 6s

Explanation / Answer

I tried for 2d array..it was going some where wrong..i did single dimensional array

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
public class HelloWorld {
public static void main(String[] args) throws Exception {
int arrayLength;
Random rn = new Random();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter arrayLength of array");
arrayLength=Integer.parseInt(br.readLine());
int temp;
int[] a=new int[arrayLength];
for(int i=0;i<arrayLength;i++)
{
int answer = rn.nextInt(7);
a[i]=answer;
}
for(int i=0;i<arrayLength;i++)
{
for(int j=0;j<arrayLength-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;

}
}
}
int count=0;
for(int i=0;i<arrayLength;i++)
{
for(int j=0;j<arrayLength;j++)
{
if(a[i]==a[j])
{
count++;

}
}
System.out.println(a[i]+" " +"occured"+count+" times");
if(count!=0)
{
i=i+count-1;
}
count=0;
}

}

}