java integer output 
	 
	
		| Author | 
		Message | 
	 
		 
		kk
 
 
 
    
		 | 
		
		
			
				  Posted: Fri Jun 04, 2004 9:13 pm    Post subject: 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!	  | code: | 	 		  // 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???   | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		rizzix
 
 
 
    
		 | 
		
		
			
				  Posted: Sat Jun 05, 2004 2:05 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				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
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Jun 05, 2004 2:34 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				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:
 
	  | code: | 	 		  
 
public class tewesf
 
{
 
        public static void main(String args[])
 
        {
 
                System.out.println(12345);
 
        }
 
}
 
  | 	  
 
 
and this code give somting compley diffrent:
 
	  | code: | 	 		  
 
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. | 
			 
			
				| Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!  | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		ify
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Jun 05, 2004 2:41 pm    Post subject: well...  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| for the numbers 1-9 you can put a zero infront and it works fine | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Dan
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Jun 05, 2004 3:24 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| 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? | 
			 
			
				| Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!  | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		rizzix
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Jun 06, 2004 2:37 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| 0 in front of a number is an octal number. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Dan
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Jun 08, 2004 11:12 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Ah, then it all makes scen now. 
 
 
I new it was coverting to some base. | 
			 
			
				| Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!  | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |