Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why does my code stop early?

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Why does my code stop early?

    The code stops after having indicated the amount of pizzas, then it sends the message of the soft drinks and stops.
    I've been trying several things, but nothing has worked, can you explain me why, I'm very new to this java.

    import java.util.Scanner;
     
    public class AP01 {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            System.out.println("¿Pepperoni or cheese pizza?");
            String piz = scan.nextLine();
            if (piz.equals("pepperoni") || piz.equals("cheese")) {
                System.out.println("¿How many will they be?");
                int quantpiz = scan.nextInt();
                System.out.println("What soda will it take, ¿Small or Large?");
                String soda = scan.nextLine();
                if (soda.equals("Small") || soda.equals("Large")) {
                    System.out.println("¿How many will they be?");
                    int quantsoda = scan.nextInt();
                }
            }
        }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Why does my code stop early?

    There is a problem when using Scanner class next... methods and nextLine methods one after the other. Read this:
    https://www.geeksforgeeks.org/why-is...ext-functions/
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. The problems (and joys?) with early adoption
    By GregBrannon in forum JavaFX
    Replies: 0
    Last Post: April 20th, 2014, 06:02 AM
  2. do while loop terminating to early
    By lupis in forum Loops & Control Statements
    Replies: 3
    Last Post: March 14th, 2012, 02:43 PM
  3. Cant get my code to stop jumping
    By Mob31 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 07:03 AM
  4. can' stop working a part of code.plzz help
    By kyros in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 30th, 2010, 03:10 PM
  5. Code Stop working after converting to jar?
    By Ron6566 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 16th, 2010, 12:17 PM