So I have this this code:
int[] player1 = new int[5]; // first player
try{
for(int i=0;i<5;i++) {
player1[i] = keyin.nextInt();}
}
catch(NumberFormatException e){
System.out.println("Player 2 : ")
}
int[] player2 = new int[5]; // Second Player
try{
for(int i=0;i<5;i++) {
player2[i] = keyin.nextInt();}
}
catch(NumberFormatException e){
System.out.println("Player 3 : ");
}
I'm trying to get the user to input 5 or less integers for betting purposes, but somehow my code keeps forcing the user to input 5 orelse it won't catch and go to the second player.. How do I change this?
nextIntshould be followed bynextLineto remove the carriage return which still remains within theSystem.inbuffer...otherwisenextIntwill fail the next time it is calledkeyin.nextLine();...