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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:39:11+00:00 2026-06-11T21:39:11+00:00

In my program the user has to choose what they want to do and

  • 0

In my program the user has to choose what they want to do and then hit the number next to the choice and then hit enter.

Right now I have it so that any number that isn’t a choice will give an error but now I want to make sure it says error if the user types in a letter for example “fadhahafvfgfh”

here is my code…

import java.util.Scanner;

public class AccountMain {


    public static void selectAccount(){


        System.out.println("Which account would you like to access?");
        System.out.println();
        System.out.println("1 = Business Account ");
        System.out.println("2 = Savings Account");
        System.out.println("3 = Checkings Account");
        System.out.println("4 = Return to Main Menu");

        menuAccount();


    }

    public static void menuAccount(){

        BankMain main = new BankMain();
        BankMainSub sub = new BankMainSub();
        BankMainPart3 main5 = new BankMainPart3();

        Scanner account = new Scanner(System.in);

        int actNum = account.nextInt();

        if (actNum == 1){

            System.out.println("*Business Account*");
            sub.businessAccount();
        }

        else if (actNum == 2){

            System.out.println("*Savings Account*");
            main.drawMainMenu();
        }

        else if (actNum == 3){

            System.out.println("*Checkings Account*");
            main5.checkingsAccount();
        }

        else if (actNum == 4){
            BankMain.menu();

        }

    }
}
  • 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-11T21:39:13+00:00Added an answer on June 11, 2026 at 9:39 pm

    You can use Scanner#hasNextInt() for this.

    if(account.hasNextInt())
      account.nextInt();
    

    Returns true if the next token in this scanner’s input can be interpreted as an int value in the specified radix using the nextInt() method. The scanner does not advance past any input.

    If user does not enter valid then you can say bye bye see you next time like below.

        int actNum = 0;
        if(account.hasNextInt()) {
            //Get the account number 
            actNum = account.nextInt();
        }
        else
        {
            return;//Terminate program
        }
    

    Else you can show error message and ask user to retry for valid account number.

        int actNum = 0;
        while (!account.hasNextInt()) {
            // Out put error
            System.out.println("Invalid Account number. Please enter only digits.");
            account.next();//Go to next
        }
        actNum = account.nextInt();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which has a text box that the user can edit.
I have a rather confusing setup for a program that lets the user choose
I have an application in which the user will choose to do a number
I'm creating a perl program where the user has to enter the name of
My program has two threads: Main execution thread that handles user input and queues
The program I am making has several views in which the user is trying
I have the following program flow: User fills in form My app generates a
I have done one program that allow user can listen to the music via
I'm writing a program where the user inputs names and then ages. The program
I have a program that has this code : #include<stdio.h> main(){ int input; char

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.