0

When I try to write "BMI" in the scanner, it doesn't even let me, it is just being stuck and I can't write anything after the println (I wrote down where it is)

import java.util.*;

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

        System.out.println("Hello, welcome to Clalit!");
        System.out.println("Login to view more options (Reply with 'Ok' below to login)");
        
        String ok = scan.next();
        ok = ok.toLowerCase();
        
        if  (ok.equals("ok")){
            System.out.println("Hello, please insert your Username");
            String name = scan.next();
            name = name.toLowerCase();
            
            if  (name.equals("galaxy")){
                System.out.println("Hello, please insert your Password");
                int pass = scan.nextInt();
                if  (pass == 12341234){
                    
                System.out.println("Welcome to Clalit, what would you like to do?");
                System.out.println("BMI/My_details/KG_to_POUNDS");
                
//Here when you write BMI for exmaple it just being stuck and you can't write anymore
       String play = scan.nextLine();
                play = play.toLowerCase();
            
                if (play.equals("bmi")){
                    System.out.println("Enter Your Height");
                    double Height = scan.nextDouble();
                
                    System.out.println("Enter Your Weight");
                    double Weight = scan.nextDouble();

                    double BMI = Weight / (Height * Height);
            
                    System.out.println("Your BMI is " + BMI);
            }
                    
                    
            
                
                
            }else{
                
                System.out.println("Wrong password, kicked");
                
            }
            
    }else {

        System.out.print("You're not welcomed!");

    }
            
            
        
            
        
        
        
            
        }

    }
}
Raz Cohen
  • 1
  • 1
  • `String play = scan.nextLine();` consumes the end of line character that you entered as part of the input for `int pass = scan.nextInt();`, because `nextInt()` doesn't consume that character. Simply add a call to `scan.nextLine()` after every call you make to `nextInt()` or `nextDouble()` and it will work. – JustAnotherDeveloper Sep 22 '20 at 16:32
  • `nextInt` for password does not consume newline, so `scan.nextLine();` returns a blank string, which does not equal "bmi", then the program is over – Michael Sep 22 '20 at 16:32

0 Answers0