Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Checking Java array

  • 03-12-2016 12:27PM
    #1
    Closed Accounts Posts: 191 ✭✭


    Hi can someone please explain why I have an error in my code... I'll post it below , thanks!


Comments

  • Registered Users, Registered Users 2 Posts: 1,470 ✭✭✭Anesthetize


    Your code looks perfect. Small, maintainable, and zero chance of bugs occurring.


  • Registered Users, Registered Users 2 Posts: 8,800 ✭✭✭Senna


    This takes cryptic code questions to a new level.

    I'm going to guess the error is on line 47


  • Registered Users, Registered Users 2 Posts: 6,271 ✭✭✭Buford T Justice


    Look to me like a runtime error - much harder to debug......


  • Registered Users, Registered Users 2 Posts: 1,712 ✭✭✭Hrududu


    NullPointerException


  • Registered Users, Registered Users 2 Posts: 6,271 ✭✭✭Buford T Justice


    Hrududu wrote: »
    NullPointerException

    Pffffttt... IndexOutOfBounds at least.....


  • Advertisement
  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    Sorry i had to go before i had a chance to reply,

    String station [] = {"Belmullet", "Mace Head","Shannon", "Valentina", "Sherkin Island" };
    String month [] = {"July", "August","September", "October"};

    double rainfall [][] = {{131.3, 96.3, 118.1, 76.3},
    {128.2, 78.8, 166.9, 60.9},
    {82.7, 93.4, 87.9, 49.7},
    {120.5, 126, 148.9, 96.1},
    {127,87,121.2,52.8}};

    for (int i=0; i<month.length;i++){
    System.out.printf("%20s", month);
    }
    for (int i=0; i<station.length;i++){
    System.out.printf("\n%-10s", station);
    }
    for (int i=0; i<rainfall.length;i++){
    System.out.println();
    for (int j=0; j<rainfall.length;j++){
    System.out.printf("%20.1f", rainfall[j]);
    }
    }
    }
    }



    How do i get the doubles on the same line as the stations just accross.


  • Registered Users, Registered Users 2 Posts: 1,470 ✭✭✭Anesthetize


    How do i get the doubles on the same line as the stations just accross.
    You need to have a loop which prints each station, and inside this loop another loop which prints the rainfall figures for each corresponding station on the same line.


Advertisement