
-----------------------------------
kk
Fri Jun 04, 2004 9:13 pm

java integer output
-----------------------------------
hi.. i have a question about java integers.  It seems when i write this code to output an integer, java outputs something totally different!// The "TestInt" class.
public class TestInt
{
    public static void main (String [] args)
    {
        System.out.println (01012004);
        // Place your code here
    } // main method
} // TestInt class
it outputs 267268!  Why is this??? :?

-----------------------------------
rizzix
Sat Jun 05, 2004 2:05 pm


-----------------------------------
hmm well its cuz the println method takes a string as an argument

concatenate the interger with a null string to automatically convert it to string:  System.out.println(1234 + "");

-----------------------------------
Dan
Sat Jun 05, 2004 2:34 pm


-----------------------------------
i dont think the problem is that it is not a string b/c println can take an int and some other values but rather the porblem is that 01012004 is not an int. Integersers or any numbe realy can not start with 0

for example this code works:

public class tewesf
{
	public static void main(String args[])
	{
		System.out.println(12345);
	}
}


and this code give somting compley diffrent:

public class tewesf
{
	public static void main(String args[])
	{
		System.out.println(012345);
	}
}



Alougth if you whont to out put the 0 in front rizzix way will work.

-----------------------------------
ify
Sat Jun 05, 2004 2:41 pm

well...
-----------------------------------
for the numbers 1-9 you can put a zero infront and it works fine

-----------------------------------
Dan
Sat Jun 05, 2004 3:24 pm


-----------------------------------
for mine it only works for 1-7, odd. I whonder what java thinks the 0 means, i know that puting a 0x infront of it gives you hex, so may be just 0 is turing it to some other base?

-----------------------------------
rizzix
Sun Jun 06, 2004 2:37 pm


-----------------------------------
0 in front of a number is an octal number.

-----------------------------------
Dan
Tue Jun 08, 2004 11:12 pm


-----------------------------------
Ah, then it all makes scen now. 

I new it was coverting to some base.
