| Author |
concatenating string and Integer
|
sri pat
Greenhorn
Joined: Oct 01, 2004
Posts: 8
|
posted

0
|
Hi, My program is below.I want the output p00000022.When i run program like this it's giving output p18. Can anybody help me. int x=00000022; String s = "p "; System.out.println(s + x ); Thanks in advance, Sri
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
A numeric literal that begins with a zero is interpreted as base 8. Therefore, 00000022 is actually 18 (2 times 8 to the first power, plus 2 times 8 to the zero power).
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
sri pat
Greenhorn
Joined: Oct 01, 2004
Posts: 8
|
posted

0
|
Hi, Is there any way i can print like this p00000022
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
|
|
You could use the java.text.DecimalFormat class. prints "p00000022".
|
[Jess in Action][AskingGoodQuestions]
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
Yes, but can you tell us more about the problem you're trying to solve? What are the requirements for these int and String variables?
|
 |
sri pat
Greenhorn
Joined: Oct 01, 2004
Posts: 8
|
posted

0
|
Excellent! Thanks Sri
|
 |
 |
|
|
subject: concatenating string and Integer
|
|
|