java - Multiarray inputs -


i unable create loop add hours multi-array. when use method hours there error. suspect for-loop not capturing input.

import javax.swing.joptionpane;  public class gain  {     // defining array names.     string[] name = {"a", “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “l”};      int[][] hours = new int[10][3];      public final int hours()      {     boolean canceled = false;     (int index = 0; index < name.length; index++) {         joptionpane.shoemessagedialog(“please enter " + name[index] + “’s hours”);             (int x = 0; x <= hours.length; x++)                (int y = 0; y <= hours[x].length; y++)         integer value = promptforint(artist[index] + “’s first hour: ”);         if (value != null) {           while (value < 0)         {             joptionpane.showmessagedialog(null, "please positive figures." + "\nplease try again.");             value = promptforint(name[index] + “’s first hour: ”);         }             pay[x][y] = value;         } else {             canceled = true;             break;         }     }      public static void main(string[] args) // main program     {         (int x = 0; x <= name.length; x++)            (int y = 0; y <= hours.length; y++)               system.out.println(x, y);     } 

try adding in brackets so:

import javax.swing.joptionpane;  public class gain  {     // defining array names.     string[] name = {"a", “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “l”};      int[][] hours = new int[10][3];      public final int hours()      {         boolean canceled = false;         (int index = 0; index < name.length; index++)         {             joptionpane.shoemessagedialog("please enter " + name[index] + "’s hours");             (int x = 0; x <= hours.length; x++)             {                 (int y = 0; y <= hours[x].length; y++)                 {                     integer value = promptforint(artist[index] + “’s first hour: ”);                     if (value != null)                     {                         while (value < 0)                         {                             joptionpane.showmessagedialog(null, "please positive figures." + "\nplease try again.");                             value = promptforint(name[index] + “’s first hour: ”);                         }                         pay[x][y] = value;                     }                      else                     {                         canceled = true;                         break;                     }                 }             }          }     }      public static void main(string[] args) // main program     {         (int x = 0; x <= name.length; x++)            (int y = 0; y <= hours.length; y++)               system.out.println(x, y);     } 

while it's fine avoid brackets in loop when have 1 line of code afterwards (like in main method), need use them when have whole block, case here in hours() method. personally, use brackets of time makes code more readable, that's me. :)


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -