• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Format Long Value

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I m writing a java program to get the sequence of number if the from no and to num is given

example
if i give from 1 to 10
the o/p is:
1
2
3
4
5
6
7
8
9
10
this works fine but whn i enter 0001 to 0010
the o/p is same as of the above.
bt i wan to display the value as follows:
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
The sample program as follows:
import java.io.*;

public class Generator{

public static void main(String args[])
{
long arg1=Long.parseLong(args[0]);
long arg2=Long.parseLong(args[1]);


try {
BufferedWriter out = new BufferedWriter(new FileWriter("generate.csv"));
for(long i=arg1;i<=arg2;i++){

out.write("\""+i+"\"");
out.write("\r\n");
}
out.close();
} catch (IOException e) {
}



}
}

any suggestions?

Thanks in advance
Santhosh
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Formatter class in the java.util package.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic