Solved

Creating 5 digit integer value

Posted on 2009-03-30
3
327 Views
Last Modified: 2012-05-06
Hi I am working in Java

I have to create min 5 digit integer value that should start with 1

for example 1 should be 00001
2 should be 00002 etc

00001
00002
...
...
99999
100000
100001
100002
...
...

and if we have a list of above values, I also need to find the earliest no from the list

Please help me with this logic

Many Thanks
0
Comment
Question by:tia_kamakshi
3 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 24019036
you can't hold integer prepadded with 0s but can be manipulated using string when you want to display or print,

for e.g.,

int i = 1 ;
System.out.println( String.format( "%05d", i ) );

would print 00001

for finding the smallest from a list, use comparator and then use Collections.sort to sort. then you can take the smallest/largest from the list!
0
 
LVL 12

Expert Comment

by:basav_com
ID: 24020699
You can create the numbers stirngs(not integers) by prepending the required number of 'Zeros'.
0
 

Author Closing Comment

by:tia_kamakshi
ID: 31564313
Many Thanks. It works great
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question