lundi 24 avril 2017

java IF statement not working for me, and I an having trouble with my variables

Hello I am trying to produce an If statement that produces a message if a user doesnt input 'M' or 'l'. If 'M' or 'l' has been inputted then the answer (4 or 5) should be displayed.

Whenever I input a letter an error pops up and if i input any number "Pizza size must be M (medium) or l (large):" message pops up. I want the to only input letters not numbers.

apologies if i havent explained the question correctly.

public static void main(String args[]) {

    char invalid;

    double M, l;    

    Scanner pizzasize = new Scanner(System.in);

    double fstep = 0, sstep = 0, tstep = 0, ostep = 0, lstep = 0;   
    M = 4;
    l = 5;
    System.out.println("Enter pizza size:");

    fstep = pizzasize.nextDouble();

    if(fstep != M|| fstep != l ){
        System.out.println("Pizza size must be M (medium) or l (large):");
    }else{
        String input = pizzasize.next();
        if(fstep == M||fstep ==l){
            fstep = M;
        }
        else if(input.equals("l")){
            fstep = l;
        }

    pizzasize.close();

}

} }

Aucun commentaire:

Enregistrer un commentaire