What am I missing with if else? [closed]

I’m a total noob at coding and started yesterday trying to learn Java. I thought I’d practice by programming a little random pizza order program (don’t ask me why, guess I like pizza).

For some reason I just can’t get the “else if” to work, even if it to me looks like it does on the tutorials I’ve watched. What am I doing wrong? Some input would be very appreciated.I have a feeling my code might be kind of bonkers in general:

    package tutorial1;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner amt = new Scanner(System.in);
        System.out.println("How many pizzas do you want?");
        int scAmt = amt.nextInt();
        Double x = scAmt * 1.3;
        System.out.println("Alright, we'll need " + x + " tons of cheese.");{
            System.out.println("What pizza do you want?");
                
            Scanner scP = new Scanner(System.in);
            String P = scP.next();
            int Margarita = 99;
            int Vesuvio = 100;
            int Hawaii = 103;
            int Kebab_Pizza = 900;
        
            if (P.equalsIgnoreCase("Margarita"));{
                System.out.println("That will be " + (Margarita) + ".");
            } 
            else if (P.equalsIgnoreCase("Vesuvio"));{
                System.out.println("That will be " + (Vesuvio) + ".");
            }
            else if (P.equalsIgnoreCase("Hawaii"));{
                System.out.println("That will be " + (Hawaii) + ".");
            }
            else if (P.equalsIgnoreCase("Kebab Pizza"));{
                System.out.println("That will be " + (Kebab_Pizza) + ".");
            }
            else {
                System.out.println("We don't serve that here.");
            }       
    }
}

Answer

Remove each semicolon(;) after your if/else if statements.

if (P.equalsIgnoreCase("Margarita")){
                System.out.println("That will be " + (Margarita) + ".");
            } 
            else if (P.equalsIgnoreCase("Vesuvio")){
                System.out.println("That will be " + (Vesuvio) + ".");
            }
            else if (P.equalsIgnoreCase("Hawaii")){
                System.out.println("That will be " + (Hawaii) + ".");
            }
            else if (P.equalsIgnoreCase("Kebab Pizza")){
                System.out.println("That will be " + (Kebab_Pizza) + ".");
            }
            else {
                System.out.println("We don't serve that here.");
            }  

Leave a Reply

Your email address will not be published. Required fields are marked *