dimanche 3 décembre 2017

JAVA:Control flow prob [duplicate]

This question already has an answer here:

This is my code, but when i try to run , when i put on scaner input number 2 , i except to ask for a input but it doesnt it goes same on the end of the file and it does output only thanks for your feedback ,even when the input is 2 or 1 ..I know the fix i just add another scan.nextLine(); but why, and how to fix it?.

 import java.util.Scanner;
 public class SelfDriving {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int rating;
    System.out.println("Please write the rating for hotel from 0-5");
    rating=scan.nextInt();

    String iks;


    if(rating>=0 && rating<=5){

        if(rating<=2){
            System.out.println("tell us the reason for low rating");
            iks=scan.nextLine();//pyet
        }
        System.out.println("thank you for your feedback");
    }
}

}

thanks

Aucun commentaire:

Enregistrer un commentaire