How to put a 1d string Array into a loop? -


im having problem inputting name in first,second,third,.. entry.. example output of code result in sth this:

ouput: input name 1 : input student hw score 1 : 2 input student test score 1 : 3 input finaltest score 1 : 2 

so problem im unable input name in loop how can fix ?

public static void main (string[] args)     {         scanner sc = new scanner(system.in);          system.out.print("contoh : ");         int noofrows;         int noofcolumns;         int[][] noofarrays;         string names[];          system.out.print("input no of students : ");         noofrows  = sc.nextint();         noofcolumns = noofrows;          //////////////////////////////////         names = new string[noofrows];             ///////////////////////         noofarrays = new int[noofrows][noofcolumns];          system.out.println("====================");          for(int = 0 ; i<noofrows ;i++)         {                 system.out.print("name "+(i+1)+" : ");                 names[i] = sc.nextline();                 system.out.print("input students hw score "+(i+1)+" : ");                 noofarrays[i][0] = sc.nextint();                 system.out.print("input student test score "+(i+1)+" : ");                 noofarrays[i][1] = sc.nextint();                 system.out.print("input finaltest score "+(i+1)+" : ");                 noofarrays[i][2] = sc.nextint();         }      } 

change names[i] = sc.nextline(); ----> names[i] = sc.next();

this work.

also,
program work number of students more 3.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -