Solved

Creating 5 digit integer value

Posted on 2009-03-30
3
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 104
runtime exception 2 65
Netbeans and org.apache.commons.lang3 issue 3 53
Where to place postgres JDBC driver jar on tomcat 8 70
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

732 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