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

  • Home
  • SEARCH
  • 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 8415231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:23:06+00:00 2026-06-10T01:23:06+00:00

Ok i am kind of new to java, but I did google search for

  • 0

Ok i am kind of new to java, but I did google search for creating methods and got mixed results so i am a bit confused on how to achieve this..
Basically I have an array which will store 20 unique account numbers, no less no more.
In addition to storing the account number i will give the option to the user to store the account balance (money, yes u guessed it this is bank account kind of homework assignment)

So the issue that i am facing is, for the process of the program run time, if the user decides to add 15accounts, i want to know how can i put the consequent accno entry in to the next free array index . and also trigger a message to say no more accounts cannot be added after capping the number of accounts at 20

public static void addAccount()
{

    int i=0;
    String accno, input;
    double accbal;
    Scanner sc = new Scanner(System.in);
    String[] accnums = new String[20];
    System.out.print("Enter the account number:");
    accno = sc.nextLine();

    if(accno.length() != 9) //the accno shld not be more than 9.
    {
        System.out.println("Wrong accnum");
    }
    else
    {
       //THis is the part i am not sure how to put the code tks.
    }

    input= accnums[1];
   System.out.println("The value:"+input);//this is just for me to display / test
}
  • 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-10T01:23:07+00:00Added an answer on June 10, 2026 at 1:23 am

    Simplest (Though not most efficient, but I don’t believe it is an issue here) can be loop and look for a null, and place it in the first null value:

    int j;
    for (j = 0; j < accnums.length; j++)
      if (accnums[j] == null) break;
    if (j==accnums.length)  {
      // error msg, the array is already full
    } else { 
      //insert element into index j
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java (but have a fair bit of .NET experience). I
I am kind of new to C (I have prior Java, C#, and some
I'm finding this kind of overriding after a new in java code very often
I've just started writing GAE web applications in Java so I'm kind of new
I am kind of new to JavaScript but I have a requirement where I
I'm kind of new in web development with Java. I am developing a web
I am kind of new to java, and I am making a MAbovePixel Generator.
I am kind of new to Java Programming and I am trying to make
I'm kind of new to java. I want to make a game. After a
I am new on Java, and its kind of difficult to me to get

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.