Solved

Creating 5 digit integer value

Posted on 2009-03-30
3
299 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
Comment Utility
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
Comment Utility
You can create the numbers stirngs(not integers) by prepending the required number of 'Zeros'.
0
 

Author Closing Comment

by:tia_kamakshi
Comment Utility
Many Thanks. It works great
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now