java - My for loops does not re run input for in.nextLine? -
i trying create program takes in name , age , stores them in respected arrays. when program run, ignores line:
personname[i] = in.nextline();
import java.util.arraylist; import java.util.arrays; import java.util.scanner; public class persons { public static void main (string[] args){ scanner in = new scanner(system.in); string[] personname = new string[9]; int[] personage = new int[9]; for(int = 0; < personname.length; i++){ system.out.println("please enter name: "); personname[i] = in.nextline(); if(!personname[i].equalsignorecase("done")){ system.out.println("please enter age: "); personage[i] = in.nextint(); } } } }
any ideas?
you have tried read integer value without reading entire line.
change line to:
personage[i] = integer.parseint(in.nextline());
Comments
Post a Comment