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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:16:55+00:00 2026-06-06T19:16:55+00:00

I am a beginner in Java and am working on a Mastermind project for

  • 0

I am a beginner in Java and am working on a Mastermind project for a course.

I have a problem. I want to retrieve the value of leftDigit and put it into array guess[4]. But I don’t know how to retrieve it outside the loop.

Let’s say when I input the number 1234 and I want it to become int[] guess = { 1, 2, 3, 4};
`

public static void inputNumber(){   

        Scanner input = new Scanner(System.in);
        currentRow++;

        System.out.printf ("Enter 4 numbers for attempt #%d: ", currentRow);

        int count = 10000, leftDigit;
        double tempNum;

        int number = input.nextInt();


        //finding the left digit   
        do{    
            tempNum = (double) number / count ;  
            leftDigit =  (int) (tempNum * 10) ;         
            count /=10;                         
            number = number - ( count * leftDigit);             
        } while (count != 1 );
    }
  • 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-06T19:16:56+00:00Added an answer on June 6, 2026 at 7:16 pm

    The solution which was posted works, but there are a few things that are unnecessary tho. Here’s the code and I’ll explain below:

    int count = 1000;                    // notice I start at 1000, not 10_000
    int[] guess = new int[4];
    int i = 0;
    
    do {
        guess[i++] = number / count;     // (1)
        number %= count;                 // (2)
        count /= 10;
    } while (count != 1)
    

    (1): because both number and count are typed int, the result will not be a floating point number and it won’t be rounding up. it’ll just truncate the floating part. For example: 8 / 3 == 2; 543 / 1000 == 0.

    (2): This line will get the remainder of the division. For example: 16 % 5 = 1; 1043 % 1000 = 43. (Another way to write this line would be number = number % count).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in Java EE and I have a problem in creating
Am Beginner to java.I have a small doubt while i am developing an application
i am a beginner at java language and i use text pad. i have
I'm totally beginner in java. In javascript i have this regex: /[^0-9.,\-\ ]/gi How
I'm a Java beginner and have been futzing around with various solutions to this
I'm a beginner java programmer. I'm working on an application that decrypts some data.
Im working on some beginner stuff in java and Im using MouseMotionListener to get
I am a java beginner and for my first project I started building a
I am Java beginner. I have developed only two Java desktop applications and I
I'm working on a beginner's java app that converts infix expressions to postfix, then

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.