• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic