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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:22:02+00:00 2026-06-18T13:22:02+00:00

I am exceptionally new to programming, but I am working on improving my skills

  • 0

I am exceptionally new to programming, but I am working on improving my skills as a programmer. Recently, I gave myself the challenge to determine what multiples of a given number are made up of distinct digits. I have gotten most of it to work, but I still need to make the code apply for every number that is a multiple of the input one. The code I have working so far is as follows:

Integer numberA = 432143;
Integer numberB = numberA;
Integer[] digitArray = new Integer[numberA.toString().length()];
int index;
for (index = 0; index < digitArray.length; index++) {
    digitArray[index] = (numberA % 10);
numberA /= 10;
}
int repeats = 0;
for (int i = 0; i < digitArray.length; i++) {
    for (int j = 0; j < digitArray.length; j++) {
    if ((i != j) && (digitArray[i]==digitArray[j])) repeats = repeats + 1;
    }
}
if (repeats == 0) {
  System.out.println(numberB);
}

This will determine if the number is made up of distinct digits, and, if it is, print it out. I have spent quite a bit of time trying to make the rest of the code work, and this is what I’ve come up with:

Integer number = 1953824;
Integer numberA = number;
Integer numberB = numberA;
for (Integer numberC = number; numberC.toString().length() < 11; 
            numberC = numberC + number) {
    Integer[] digitArray = new Integer[numberA.toString().length()];
    int index;
    for (index = 0; index < digitArray.length; index++) {
        digitArray[index] = (numberA % 10);
        numberA /= 10;
    }
    int repeats = 0;
    for (int i = 0; i < digitArray.length; i++) {
        for (int j = 0; j < digitArray.length; j++) {
            if ((i != j) && (digitArray[i]==digitArray[j])) repeats = repeats + 1;
        }
    }
    if (repeats == 0) {
        System.out.println(numberB); 
    }
}

I can’t figure out why, but his just prints whatever the number is a bunch of times if it is made up of distinct digits, and leaves it blank if it is not. If anyone could tell me why this is occurring, or even tell me what I need to do to fix it, that would be superb. Remember, I am very new to programming, so please give a short explanation for any terms you use that are at all out of the ordinary. I am eager to learn, but I currently know very little. Thank you for your time, and I greatly appreciate any and all help you can give me.

  • 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-18T13:22:03+00:00Added an answer on June 18, 2026 at 1:22 pm

    You assign the value of numberA to numberB (which is the value of number) right before the for loop. After that, numberB is never modified or assigned to a new value, so for every pass through the for loop, you’re simply printing the value of numberB, which is always 1953824 in this case.

    There are several corrections that can be made to achieve the result you desire, while cleaning up the code a little. The first thing is to change the print statement to print the correct number:

    System.out.println(numberC);
    

    Since numberC is the variable that is being updated by the for loop, that’s what you’ll want to conditionally print out if there are no repeat digits. Since we’ve replaced numberB with numberC, that means numberB is not longer needed, you can delete the declaration for it.

    Now, the next issue is when you’re defining the digital array – you should use the length of numberC, not numberA. Also, inside the for loop, you should assign numberA the value of numberC, or else eventually nothing but 0s will be stored in your digitArray. Overall, here’s what it should look like.

        Integer number = 1953824;
        Integer numberA = number;
    
        for (Integer numberC = number; numberC.toString().length() < 11; 
                        numberC = numberC + number) {
    
            Integer[] digitArray = new Integer[numberC.toString().length()];
            numberA = numberC;
            int index;
            for (index = 0; index < digitArray.length; index++) {
                digitArray[index] = (numberA % 10);
                numberA /= 10;
            }
            int repeats = 0;
            for (int i = 0; i < digitArray.length; i++) {
                for (int j = 0; j < digitArray.length; j++) {
                    if ((i != j) && (digitArray[i] == digitArray[j]))
                        repeats = repeats + 1;
                }
            }
            if (repeats == 0) {
                System.out.println(numberC);
            }
        }
    

    This should produce the desired result. It seems to work on my machine 🙂

    If you want, you can take Jeffrey’s suggestion and change the Integer to the primitive int to avoid the overhead of boxing. However, you still need to use the Integer class to use the toString() method, but you can accomplish that using Integer.valueOf():

    Integer.valueOf(numberC).toString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am exceptionally new to programming, but I am working on improving my skills
Now I am exceptionally new to network programming so tell me if this is
It seems exceptionally heavy handed but going by the rule anything publicly available should
I'm working on a programming language that uses C++ as it's target language for
I am very new to VB.net and I am finding it exceptionally difficult to
I'm new to Ruby on Rails but it seems it creates a new session
I recently made the switch to a new job and consequently the switch from
I'm new to programming and I have a conceptual question. That is, can exception
As I was working on a project, I thought to myself Hmmm, it would
I don't know much about web development, so probably this question will sound exceptionally

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.