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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:58:14+00:00 2026-06-12T11:58:14+00:00

I am a beginner in programming (learning Java). I am trying to write a

  • 0

I am a beginner in programming (learning Java). I am trying to write a program in which I list four different options for the user to choose from.

Here is part of it:

import java.util.*;
    public class fight {

            public static int upgrade1 = 0;
            public static int upgrade2 = 0;
            public static int upgrade3 = 0;
            public static int upgrade4 = 0;

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        System.out.println("Please enter your name:");

            String player = scan.next();    

System.out.println("You have earned 2 upgrade points. Which of the following traits would you like to boost by 2 points?\n"
    + " 1. upgrade1\n 2. upgrade2\n 3. upgrade3\n"
    + " 4. upgrade4");

                    if (scan.nextInt() == 1) {
                        upgrade1 = upgrade1 + 2;
                            System.out.println("Your upgrade1 level is now: " + upgrade1);
                    }
                    else if (scan.nextInt() == 2) {
                        upgrade2 = upgrade2 + 2;
                            System.out.println("Your upgrade2 level is now: " + upgrade2);
                    }
                    else if (scan.nextInt() == 3) {
                        upgrade3 = upgrade3 + 2;
                            System.out.println("Your upgrade3 level is now: " + upgrade3);
                    }
                    else if (scan.nextInt() == 4) {
                        upgrade4 = upgrade4 + 2;
                            System.out.println("Your upgrade4 level is now: " + upgrade4);
                    }                                                       
        }
} 

The problem is: When the user enters which option they want to pick, they must enter the number (x being the number they choose) x amount of times. For instance, the user wants to choose option 3. They must enter the number 3 three times into the console before it understands and completes the next line.

Here is the console after running the program:

Please enter your name:
rick
Hello, rick. You have earned 2 upgrade points. Which of the following traits would you like to boost by 2 points?
1. upgrade1
2. upgrade2
3. upgrade3
4. upgrade4
3
3
3
Your upgrade3 level is now: 2

I hope this makes sense, and any help is much appreciated (I assume I’m just making a dumb rookie error). Also, if you have any constructive criticism about the way it’s structured, please don’t hesitate. Thanks!

  • 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-12T11:58:15+00:00Added an answer on June 12, 2026 at 11:58 am

    This is because you are calling scan.nextInt() in every if/else if statement. What you want to do is store the value they entered and then check the value in the if/else if statements, otherwise you’re basically prompting the user for input multiple times.

    int input = scan.nextInt();
    
    if (input == 1) {
        upgrade1 = upgrade1 + 2;
            System.out.println("Your upgrade1 level is now: " + upgrade1);
    }
    else if (input == 2) {
        upgrade2 = upgrade2 + 2;
            System.out.println("Your upgrade2 level is now: " + upgrade2);
    }
    else if (input == 3) {
        upgrade3 = upgrade3 + 2;
            System.out.println("Your upgrade3 level is now: " + upgrade3);
    }
    else if (input == 4) {
        upgrade4 = upgrade4 + 2;
            System.out.println("Your upgrade4 level is now: " + upgrade4);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner to C programming. I'm trying to learning how to code a
I am learning Python, following a book (Python Programming for the Absolute Beginner, 3rd
I'm a beginner in programming. I've just made a program called Guessing Game. And
I am currently learning python programming (and am a beginner at it). Currently I
I'm sort of learning C, I'm not a beginner to programming though, I know
I'm learning C# now and a beginner in the programming world. I have a
Complete programming beginner just trying to clarify something, I was creating keys for a
First i am a beginner in programming in general, i am trying to create
I started learning android programming a couple of weeks ago. I am a beginner
I am a beginner in programming Java Desktop Application interacting with databases. My goal

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.