Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    This code compiles empty, meaning there is really no output. Can anyone explain why?

    This code compiles empty. Can anyone explain why?
    class ArrayDemo {
    public static void main(String[] args) {
    // declares an array of integers length "size"
    int[] anArray;
    int i = 0;
    int size = 10;
    anArray = new int[size];

    // initialize array
    for(i=0; i<size; i++) {
    anArray[i] = i*100;
    }

    for(i=0; i<size; i++) {
    System.out.println("Element at index " + i + ": " + anArray[i]);
    }
    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Works for me.
    In the future please wrap your code in [code][/code] or [php][/php] tags to preserve formatting.

  • #3
    New Coder
    Join Date
    Dec 2011
    Location
    abuja
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ordinarily, this code should work. But you have an unnecessary for-loop statement. Debug the second for-loop statement, then copy the output statement and paste inside the first for-loop statement. Try it. Hope you got it?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •