Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:47:26+00:00 2026-06-03T12:47:26+00:00

I’m relatively new to programming. I’m trying to make a program at the moment,

  • 0

I’m relatively new to programming.
I’m trying to make a program at the moment, and I’m trying to figure out how I can do something. I hope you guys can help me as I just don’t know how to do this…

So, first of all, I have made an array and filled it with stuff:

String[] pizza = new String[10];
    pizza[0] = "1- Cheese";
    pizza[1] = "2- Wedge";
    pizza[2] = "3- Bacon";
    pizza[3] = "4- Hawaiian";
    pizza[4] = "5- Vegetarian";
    pizza[5] = "6- Pepperoni";
    pizza[6] = "7- Ham";
    pizza[7] = "8- Apple";
    pizza[8] = "9- Grape";
    pizza[9] = "10- Italian";

I want to make it so that I have an IF statement (which is inside a while). I’ll just put the code here, and explain after.

int pizzaCounter = 0;

        while(pizzaCounter < 5)
        {

            Scanner pizzaPick = new Scanner(System.in);
            int Pizzas = pizzaPick.nextInt();

            if (Pizzas == 1)
            {
                *Store "1- Cheese" (From pizza[0]) into a variable*

                pizzaCounter++;
            }
            if (Pizzas == 2)
            {
                *Store "2- Wedge" (From pizza[0]) into a variable*

                pizzaCounter++;
            }
            if (Pizzas == 3) etc...

        }

Now at the ‘Insert something here’ bit, I want to try to make it so that it stores the text from the array(pizza) into some variable which I can print out later… So for example if the user inputs ‘1’ then it takes: “1-Cheese” and stores it in a variable which I can print out later…

Also, I want to make it clean, so that there aren’t 10 IF statements prompting each variable thing…?

I don’t know if this is even possible, but any help is greatly appreciated! 😀

I hope what I am asking here is understandable…

Please, if possible, could you explain what you are doing at each of the steps, so that I can actually understand what is happening, and maybe use the same code later, instead of just copying it and pasting the code? I’m kind of a noob so I think that the more I learn the more I can use later on… Thanks so much! 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:47:32+00:00Added an answer on June 3, 2026 at 12:47 pm

    You can replace the entire series of if statements with something like:

    string saveName = "";
    if ((Pizzas >= 0) && (Pizzas <= 9)) {
        saveName = pizza[Pizzas];           // This is "insert something here".
        pizzaCounter++;
    }
    
    // Here, saveName has the pizza name.
    

    For a full blown program which allows you to order up to five pizzas, saving the lot and printing them out at the end, see below:

    import java.util.Scanner;
    
    public class testprog {
        public static void main (String args[]) {
            String[] pizzaList = {" 0 - End of order",
                " 1 - Cheese", " 2 - Wedge", " 3 - Bacon", " 4 - Hawaiian",
                " 5 - Vegetarian", " 6 - Pepperoni", " 7 - Ham", " 8 - Apple",
                " 9 - Grape", "10 - Italian"};
    
            int[] orderList = new int[5];  // Ordered pizzas
            int pizzaCount = 0;            //    and count.
    
            Scanner pizzaPick = new Scanner(System.in);
            while (pizzaCount < 5) {
                // Output the menu.
    
                System.out.println ("Choose a pizza:");
                for (int i = 0; i < pizzaList.length; i++)
                    System.out.println ("   " + pizzaList[i]);
    
                // Get input, check, and add pizza.
    
                int thisPizza = pizzaPick.nextInt();
                if (thisPizza == 0) break;
    
                if ((thisPizza > 0) && (thisPizza < pizzaList.length))
                    orderList[pizzaCount++] = thisPizza;
    
                if ((thisPizza < 0) || (thisPizza >= pizzaList.length))
                    System.out.println ("Invalid input of " + thisPizza);
            }
    
            // Output all pizzas.
    
            for (int i = 0; i < pizzaCount; i++)
                System.out.println ("Ordered: " + pizzaList[orderList[i]]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.