# Need Urgent help, very easy code just missing some needed knowledge

• July 14th, 2013, 07:23 AM
Seraphim
Need Urgent help, very easy code just missing some needed knowledge
public class BasicExamRevision1 {
public static void main(String[] args) {
int i, j, z, y, x;
int count = 0;
int RanArray [] = new int[30];
int countArray[] = new int[10];
for(i=0;i<RanArray.length;i++){
RanArray[i] = (int)(Math.random()*90+10);
System.out.println("These are the numbers in the array: at slot "+ (i+1) + " " + "we have: " + RanArray[i]);
}//end of for loop
for(z=0;z<RanArray.length;z++){
for(y=z+1;y<RanArray.length;y++){
if(RanArray[z]>RanArray[y]){
j = RanArray[z];
RanArray[z] = RanArray[y];
RanArray[y] = j;
z=0;
y=0;
}//end of if statement
}//end of y for loop
}//end of z for loop
for(i=0;i<RanArray.length;i++){
System.out.println("The numbers are: " + RanArray[i]);
}//end of i for loop
for(i=0;i<RanArray.length;i++){
for(j=10;j==100;j=j+10){
if(RanArray[i]>=j-10 && RanArray[i]<=j){
countArray[j/10] = countArray[j/10]+1;
}//end of if statement
}//end of j for loop
}//end of i for loop
for(j=0;j<countArray.length;j++){
System.out.println("These are in the certain intervals " + countArray[j]);
}//end of j for loop
}//end of psvm
}//end of public class

I don't understand why the last two nested for loops with countArray wont work because it just keeps returning 0 for all place holders of countArray in the last for loop. I need serious help with it before my exams. Any help will help me alot. I really need it. Thank you.
• July 14th, 2013, 09:38 AM
vijayj196
Re: Need Urgent help, very easy code just missing some needed knowledge
Hi friend , can you give me problem statement of the code that you have written here

--- Update ---

Hi Dear your problem is solved . All the best for exams
Solution for above problem:
...
• July 14th, 2013, 11:01 AM
copeg
Re: Need Urgent help, very easy code just missing some needed knowledge
@vijayj196, welcome to the forums. Please read the forum announcements and the following:
http://www.javaprogrammingforums.com...n-feeding.html
• July 14th, 2013, 12:16 PM
vijayj196
Re: Need Urgent help, very easy code just missing some needed knowledge
Hi,
you have made little mistake in writing two nested for loop . You can count number of numbers between certain range as follows:
Suppose , You have array1 containing numbers and array2 that will contain count.
step1: You have to access each number in array1.
step2: check is number lies in specified interval e.g. 0 to 10
step3: if yes then increment count
step4: After counting all elements you need to store it in count array
I hope this will help you understanding how to use nested loops
• July 14th, 2013, 12:57 PM
Seraphim
Re: Need Urgent help, very easy code just missing some needed knowledge
Thanks that helped.

--- Update ---

I did figure it out in the end. but yes thank you for your teaching @vijay196