Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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,465 ✭✭✭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,262 ✭✭✭Buford T Justice


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


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


    NullPointerException


  • Registered Users, Registered Users 2 Posts: 6,262 ✭✭✭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,465 ✭✭✭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