Solved

Creating 5 digit integer value

Posted on 2009-03-30
3
318 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

785 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