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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:50:09+00:00 2026-06-11T09:50:09+00:00

I am trying to create a random four digit number and then use decimal

  • 0

I am trying to create a random four digit number and then use decimal format to print it out as (# * 1000) + (# * 100) + (# * 10) + (# * 1). For example, say i generate 7956 it would take that, split it up and print out as (7 * 1000) + (9 * 100) + (5 * 10) + (6 * 1). So far this is what I have:

public static void main(String [] args)
{
    Random random = new Random();
    int number = random.nextInt(10000);


    DecimalFormat formatOne;
    formatOne = new DecimalFormat("(# * 1000) + (# * 100) + (# * 10) + (# * 1)");

    System.out.println("The random number was: " + number);
    System.out.println("Which is: " + formatOne.format( random.nextInt(10000) ) );


}

I was thinking I’d be able to use just that format, but since 0 is any number including zero it won’t print it out correctly. I’ve tried splitting it up, but it ends up just taking the zeros from the number i’m multiplying by and putting them on the end of the first number. I am in a fairly low level java class, and haven’t even gotten to loops yet so if you could keep this as simple as possible it would be greatly appreciated. Thank you for any and all help!

  • 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-11T09:50:11+00:00Added an answer on June 11, 2026 at 9:50 am

    DecimalFormat doesn’t work that way.

    You’ll have to do it in code.

    You might consider getting the number as a String, then iterating backwards (last to first) over its characters in a loop that builds up the output you want.

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

Sidebar

Related Questions

I'm trying to figure out a way to create random numbers that feel random
I am trying to create a transparent image canvas and then place other random
I'm trying to create a simple loop that adds a random number of stars,
i'm trying to create a random number generator that will generate number based on
We are trying to create a random number generator to create serial numbers for
I'm trying to use ccDrawPoly to create some random looking asteroid-like polygons. To do
I'm trying to create a random number generator that generates random numbers between two
I'm trying to create a random generator and on another page if found a
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
Trying to create a macro which can be used for print debug messages when

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.