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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    8
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exclamation 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. #2
    Junior Member
    Join Date
    Jul 2013
    Location
    Aurangabad
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
    ...
    Last edited by copeg; July 14th, 2013 at 10:00 AM. Reason: Removed spoonfeeding

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,273
    Thanks
    177
    Thanked 822 Times in 765 Posts
    Blog Entries
    5

    Default 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. #4
    Junior Member
    Join Date
    Jul 2013
    Location
    Aurangabad
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    8
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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

Similar Threads

  1. My Code is not working [URGENT] Help Needed
    By abhijit@92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 25th, 2012, 03:37 PM
  2. Easy calculate coding needed.
    By mic2bless in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 2nd, 2012, 06:18 AM
  3. Help please - urgent (Project due and not done) - Easy answer
    By Bagzli in forum Java Theory & Questions
    Replies: 1
    Last Post: March 2nd, 2011, 05:36 PM
  4. Urgent help needed
    By mohit1007 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 23rd, 2010, 09:34 PM
  5. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM

Tags for this Thread