aspose file tools
The moose likes Java in General and the fly likes concatenating string and Integer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "concatenating string and Integer" Watch "concatenating string and Integer" New topic
Author

concatenating string and Integer

sri pat
Greenhorn

Joined: Oct 01, 2004
Posts: 8
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
Hi,
Is there any way i can print like this p00000022
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24041
    
  13

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
Excellent!
Thanks
Sri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: concatenating string and Integer
 
Similar Threads
Not able to understand the output
declaring throws Exception after main()
How to split a string by the whitespace but ignoring '\n'?
URLEncoder()
doubt about the program???