| | |
how use integer values begins with zero
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
You cannot store an integer value as an integer, and with a leading zero. I assume you only need the leading zero when printing the number, right?
Than look into the format method for String, if you are using at least 1.5. (And follow the "format string" link found in the method description for format.
Than look into the format method for String, if you are using at least 1.5. (And follow the "format string" link found in the method description for format.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
while printing only..if you want that leading zero means..i think only the way you should use string... and after that you want it as integer value means just parse it as integer...
try like this....
public class strtes
{
public static void main(String args[])
{
int x=12;
int y=10;
String a="0"+x;
String b="0"+y;
int z=Integer.parseInt(a);
int z1=Integer.parseInt(b);
System.out.println(a);
System.out.println(b);
System.out.println(z);
System.out.println(z1);
}
}
try like this....
public class strtes
{
public static void main(String args[])
{
int x=12;
int y=10;
String a="0"+x;
String b="0"+y;
int z=Integer.parseInt(a);
int z1=Integer.parseInt(b);
System.out.println(a);
System.out.println(b);
System.out.println(z);
System.out.println(z1);
}
}
Adios,
Vinod......
Vinod......
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
I assume the number should have a specific length front padded with zeros, right? i.e.
001
002
055
100
Well, then as I said, follow the link for "format string". You call tell format that you want the number to be three digits long and front padded with zeros. Then you do not have to decide when to pad, format will.
So, I need to ask, did you actually read what I told to read, and attempt to figure it out, or do you just want "teh codes" (mispelled on purpose).
001
002
055
100
Well, then as I said, follow the link for "format string". You call tell format that you want the number to be three digits long and front padded with zeros. Then you do not have to decide when to pad, format will.
So, I need to ask, did you actually read what I told to read, and attempt to figure it out, or do you just want "teh codes" (mispelled on purpose).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- integer values into array (Community Introductions)
- Comparing Python and C, Part 1, Integer Variables (Python)
- help needed in assigning values.. (C)
Other Threads in the Java Forum
- Previous Thread: I want to disable the copy option
- Next Thread: string tokenizer
Views: 4328 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie number object objects oracle oriented panel print printf problem program programming project projects recursion replaydirector reporting researchinmotion return robot rotatetext scanner screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






