Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

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

1. ## 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.

2. ## 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:
...

3. ## 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:
The Problem with Spoon-feeding

4. ## 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

5. ## 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