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 6743173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:55:47+00:00 2026-05-26T11:55:47+00:00

I am trying to do a switch inside of a switch. Ive gotten it

  • 0

I am trying to do a switch inside of a switch. Ive gotten it to compile, but the only thing is, every time I run it, I select one of the cases for the first switch, and once I go and select one of the cases for the first switch inside of the switch, it then also asks for me to select a case for the second switch inside of the first switch, then the third and forth, then it ends. How do I either make the entire program start again back at the beginning after selecting the first switch inside of the switch, or end the program. Thanks.

ex.

System.out.println("Pick a color.\n");

System.out.println("          1. Red");
System.out.println("          2. Blue");
System.out.println("          3. Yellow");
System.out.println("          4. Green");

Scanner kbReader = new Scanner(System.in);
int color = kbReader.nextInt();

System.out.println("The color you chose was " + color + ".");
String s1 = kbReader.nextLine();

switch (color)
    {
case 1: //Red
System.out.println("Now enter an integer from 1 through 10.");
int num1 = kbReader.nextInt();

switch (num1)
        {
case 1:
case 3:
case 5:
case 7:
case 9:
    System.out.println("");

case 2:
case 4:
case 6:
case 8:
case 10:
    System.out.println("");
    break;
        }
case 2: //Blue
System.out.println("Now enter an integer from 1 through 10.");
int num2 = kbReader.nextInt();

switch (num2)
        {
case 1:
case 3:
case 5:
case 7:
case 9:
    System.out.println("");

case 2:
case 4:
case 6:
case 8:
case 10:
    System.out.println("");

        }
case 3: //Yellow
System.out.println("Now enter an integer from 1 through 10.");
int num3 = kbReader.nextInt();

switch (num3)
        {
case 1:
case 3:
case 5:
case 7:
case 9:
    System.out.println("");

case 2:
case 4:
case 6:
case 8:
case 10:
    System.out.println("");

        }
case 4: //Green
System.out.println("Now enter an integer from 1 through 10.");
int num4 = kbReader.nextInt();

switch (num4)
        {
case 1:
case 3:
case 5:
case 7:
case 9:
    System.out.println("");

case 2:
case 4:
case 6:
case 8:
case 10:
    System.out.println("");     
        }
    }
}
  • 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-05-26T11:55:48+00:00Added an answer on May 26, 2026 at 11:55 am

    Just put a break after the switch statements that are inside the switch statements.

    i.e. (for exampe)

    switch (color) 
        { 
    case 1: //Red 
    System.out.println("Now enter an integer from 1 through 10."); 
    int num1 = kbReader.nextInt(); 
    
    switch (num1) 
            { 
    case 1: 
    case 3: 
    case 5: 
    case 7: 
    case 9: 
        System.out.println(""); 
    
    case 2: 
    case 4: 
    case 6: 
    case 8: 
    case 10: 
        System.out.println(""); 
        break; 
            } 
    
    break;  <--- this is the addition
    case 2: //Blue 
    

    Alternatively (and would make the whole thing more readable) put those switches into another function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really trying to switch to emacs, but learning to setup the environment is
I am trying to have an h:inputText switch out with a different one when
I'm trying to access an arrays data from inside a function but keep getting
I'm trying to switch from CellTable to DataGrid. The actual change was very easy
I have never code in Python and trying to switch from Javascrpt/SVG. Being confused
I have a Jekyll blog, I am trying to switch from this {:lang='bash'} #!/bin/sh
When trying to use a Switch Case with switch(string) for an android project ,
I'm trying to use jquery to switch between three images once you click on
I'm trying to suppress task switch keys (such as winkey , alt + tab
I'm trying to build a switch and I get an expression must have integral

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.