vendredi 8 avril 2016

why does my scanner(system.in) run twice

I am new to java, been self teaching for the last week. I cannot find the reason why the if else statement runs twice.

public static void main(String[] args) {
    //program designed to ask how many visitors
    //are in a party of people and work out
    //the total cost of the entry tickets.
    double adult = 12.50;
    double consession = 9.90;
    double child = 6.25;
    double percentage = 0.80;

    System.out.println("please enter the amount of adults");
    Scanner adult1 = new Scanner (System.in);

    //adding code that would give a percentage discount for 
    //4 adults or more
    {   
        if ( adult1.nextInt() >= 4)
        {
            double adult2 =( adult1.nextInt() * percentage);
        } else {
            double adult2 = (adult * adult1.nextInt());

Aucun commentaire:

Enregistrer un commentaire