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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:37:53+00:00 2026-06-10T06:37:53+00:00

This is very interesting, i notice. Before i can explain further its best i

  • 0

This is very interesting, i notice. Before i can explain further its best i show the code and you will understand what i mean.

This is the code:

public class Qn3 {
    static BigDecimal[] accbal = new BigDecimal[19];
    private static Integer[] accnums = new Integer[19];

    public static void main(String[] args) {
        addaccount();

    }
    public static void addAccount() {

        int i = 0, accno, input, j, check;
        BigDecimal accbala;
        DecimalFormat df = new DecimalFormat("0.00");

        Scanner sc = new Scanner(System.in);
        Scanner in = new Scanner(System.in);
        accnums[1] = new Integer(1);

        while (accnums.length >= count(accnums)) {
            System.out.print("Enter the account number: ");
            while (sc.hasNext("[0-9]{7}")) {
                accno = sc.nextInt();
                System.out.print("Enter account balance: ");
                accbala = in.nextBigDecimal();

                for (j = 0; j < accnums.length; j++) {
                    if (accnums[j] == null)
                        break;
                    else if (accnums[j].equals(accno)) {
                        break;
                    }
                }

                if (j == accnums.length) {
                    System.out.print("No more than 20 accounts can be added.");
                } else if (accnums[j] != null) {
                    if ((accnums[j].equals(accno)))
                        System.out.println("Account already exists");
                    break;
                } else {
                    accnums[j] = accno;
                    accbala = accbala.setScale(2, RoundingMode.HALF_UP);
                    accbal[j] = accbala;
                    check = j;
                    System.out.println("Current number of accounts in the system: "
                                    + (check + 1)
                                    + "\nNumber of accounts still can be added: "
                                    + (20 - (check + 1)));

                }
            }

            while (!sc.hasNext("[0-9]{7}")) {
                System.out.println("Wrong NRIC");
                break;
            }
            while (accnums.length <= count(accnums)) {
                System.out.println("20 accounts have already been created");
                break;
            }
            break;
        }
    }

    private static int count(Integer[] array) {
        int count = 0;
        // accnums = new Integer[] {1,2};
        for (int index = 0; index < array.length; index++) {
            if (array[index] != null) {
                count++;
            }
        }
        // System.out.println("You have used " + count + " slots");
        return count;
    }
}

So now that you have seen the code the problem that is hard to notice is this, take note of the line in the addaccount() method where

 System.out.println("Current number of accounts in the system: "+(check+1)+"\nNumber of accounts still can be added: "+(20 - (check+1)));

this line the first check+1 will give me 1 then the next one gives me 3! and then the next time i run the method it gives me 4 and then again 5 and so on so forth, what is happening to 2?

  • 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-10T06:37:55+00:00Added an answer on June 10, 2026 at 6:37 am

    You have that println in an else block, and when j == 1 you’re hitting the else if case. Try removing this line

    accnums[1] = new Integer (1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there's this interesting problem i can not solve myself. I will be very glad,
Found this very interesting code on total variation filter tvmfilter The additional functions this
I'm generally not a fan of microbenchmarks. But this one has a very interesting
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
In this very simple code example, messages get lost every once in a while.
This is a very interesting thing. I have an APK file, com.company.app.apk. When installed
After reading this very interesting topic on stackoverflow --> How to wait for COM
This is very interesting.. I want to have multiple gridviews in a panel. and
I have a very interesting problem. I use this technologies in WPF app: Caliburn.Micro
I came across this very interesting question? I have 300 million SSN numbers (9

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.