samedi 2 février 2019

If statements keep on repeating even when conditional statement is false

Dr Java

Every time I write run PizzaCalc 2 3 4 5 6 it just displays every system.out.print no matter if the first number is 1 or 2 and if its 1 it just doesnst work Im a beginner started yesterday

public class PizzaCalc {

    public static void main(String[] args) {

        int a = Integer.parseInt(args[0]); 
        double b = Double.parseDouble(args[1]);
        double c = Double.parseDouble(args[2]);        
        double d = Double.parseDouble(args[3]);
        double e = Double.parseDouble(args[4]);

        double sum2 = (Math.pow(d,2))*c*e/(Math.pow(b,2));
        double sum1 = (Math.pow(b,2))-(Math.pow(c,2));

        if     (a==2) 
        {
                System.out.print("You chose Price mode");
                System.out.println("The diameter of the large pizza is " + b + " inches");    
                System.out.println("The price of one large pizza is " + c + " dollars");
                System.out.println("The diameter of the small pizza is " + d + " inches");
                System.out.println("You want to buy " + e + " small pizzas");
                System.out.println("The fair price to pay for " + e + " small pizzas is " + sum2 + " dollars"); 
        } if  (a==1);   
        {       
                System.out.print("You chose Quantity mode");
                System.out.println("The diameter of the large pizza is " + b + " inches");
                System.out.println("The diameter of the small pizza is " + c + " inches");  
                System.out.println("You should order " + sum1 + " small pizzas");
        } if (a!=1 && a!=2); 
        {
                System.out.print("You have selected an invalid mode");
        }
    }   
}    

Aucun commentaire:

Enregistrer un commentaire