1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package dandd.aanda;
import java.util.Scanner;
public class TestPrintf { public static void main(String[] args) { String yes = "yes"; String no = "no"; System.out.println("type yes or no"); Scanner input = new Scanner(System.in);
String line = input.nextLine(); if (line.equals(yes)) { System.out.println("Follow me then boooyyyoo!!!!"); } else if (line.equals(no)) { System.out.println("Alright then laddy, you just going to sit on the porch all day and crrry then?"); } else { System.out.println("that didn't help me, yes or no?"); } } |
Try that ^
When you call input.nextLine(), it waits for input, so first it waits for input, then checks if it's yes. Then it waits for input again, and checks if it's no. to solve it, just call input.nextLine() once, and store it in a variable.
EDIT: Dammit UprightPath! I thought I was helping someone, and I get "Warning - while you were typing a new reply has been posted. You may wish to review your post." Why am I always too slow to help people?