Skip to toolbar

Difference between int x= 10 and y=010 in Java.

Logically there is no difference between 10 and 010 in numbers. But in java, there is a difference of presentation and actual values of these numbers.

Int x = 10;

System.out.println(x);                      // Output: 10

Int y = 010;

System.out.println(y);                      // Output: 8

Exactly when we print 010 it actually prints 8 which is Octal value of digit 010.

You must learn about Octal base(8) number system before starting the code review.




Code Example:

/**
 * @author ashok.kumar
 *
 */
public class Test1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int i=1;
		
		System.out.println("Numeric:" + i);
		
		int j=01;
		
		System.out.println("Numeric:" + j);
		
		int k=00;
		
		System.out.println("Numeric:" + k);
		
		int l=10;
		
		System.out.println("Numeric:" + l);
		
		
		int m=010;
		
		System.out.println("Octal value:" + m);
		
		int n=0100;
		
		System.out.println("Octal value:" + n);
		
                int o=0110;
		
		System.out.println("Octal value:" + o);
		
		int mn=1110;
		
		System.out.println("Numeric:" + mn);
		
		int jk=0112;
		
		System.out.println("Octal value: "+jk);
		
		int temp=0111;
		
		System.out.format("Display in Octal format: %04o",temp);	
	}
}

Output:
Numeric:1
Numeric:1
Numeric:0
Numeric:10
Octal value:8
Octal value:64
Octal value:72
Numeric:1110
Octal value: 74
Display in Octal format: 0111



3401total visits,9visits today

Leave a Reply

Your email address will not be published. Required fields are marked *

Site Statistics

  • Users online: 0 
  • Visitors today : 14
  • Page views today : 24
  • Total visitors : 48,400
  • Total page view: 66,592

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.