I am a beginner in Java programming and I have encountered an problem. If you look at my code: `package whileloops;
import java.util.Scanner;
public class Empty_The_Piles {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int pileA, pileB, pileC;
pileA = 3;
pileB = 3;
pileC = 3;
int piletotal = pileA + pileB + pileC;
while(piletotal >= 0){
String pile = "";
System.out.println("A: " + pileA + "\tB: " + pileB + "\tC: " + pileC);
System.out.println("\nChoose a pile: ");
pile = keyboard.nextLine(); //After 1 loop it jumps over this line or something..
System.out.println("How many fishes do you want to remove from pile " + pile + "?");
int amount = keyboard.nextInt();
if(pile.equals("A"))
pileA = pileA - amount;
else if(pile.equals("B"))
pileB = pileB - amount;
else if(pile.equals("C"))
pileC = pileC - amount;
else
System.out.println("ERROR. NO SUCH PILE!");
}
System.out.println("All piles are empty! Nice work!");
}
}
EDIT: When the code is on it's second loop it suddenly jumps over it. When I run the code the first time it pick's it up fine, but when it loops back to the start it jumps over pile = keyboard.nextLine();
It jumps directly to the next line... It doesn't wait for an input
If I try what the other thread you said was the answer, I need to type it in two times.
Guess this is easy for most of you :P
- Thanks for the help :)