java - Why is my program only letting me input one value after the first iteration of the for loop? -
this question has answer here:
i extremely new java programming , trying make poker hand evaluator. asking suit , value of card, using loop. reason, works first iteration of loop asks me 1 value after that. here code:
import java.util.scanner; public class pokerrun { public static void main(string[] args) { int [] suit = new int[5]; int [] value = new int[20]; card card1 = new card(); scanner in = new scanner(system.in); int counter = 1; system.out.println("welcome poker hand evaluator!"); for(int = 1; i<6; i++) { system.out.println("what suit of card " + + "?\nplease type suit in lowercase letters: "); card1.suit = in.nextline(); system.out.println("what value of card " + + "? (j = 11, q = 12 k = 13, = 14"); card1.value = in.nextint(); //checks if face card, if true, changes card.facecard if(card1.value == 11) card1.facecard = "jack"; else if(card1.value == 12) card1.facecard = "queen"; else if(card1.value == 13) card1.facecard = "king"; else if(card1.value == 12) card1.facecard = "ace"; if(card1.value<11) system.out.println("you entered " + card1.value + " of " + card1.suit + "."); else system.out.println("you entered " + card1.facecard + " of " + card1.suit + "."); } } }
rohit jain, yes problem.
my suggestion solution exchange line
card1.value = in.nextint();
with:
card1.value= integer.parseint(in.nextline());
this should work you.
to explain bit more scanner build string parsing of files etc. , not commandline inputs. use bufferedreader:
bufferedreader reader = new bufferedreader(new inputstreamreader(system.in)); reader.readline();
Comments
Post a Comment