Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java integer handling

Tags:

java

When I run this program, it outputs -43.

public class Main {
    public static void main(String[] args) {
        int a=053;
        System.out.println(a);
    }
}

Why is this? How did 053 turn into -43?

like image 819
mriganka3 Avatar asked May 02 '11 04:05

mriganka3


People also ask

Is Java int 32 or 64 bit?

int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1.

What is integer [] in Java?

In Java, int is a primitive data type while Integer is a Wrapper class. int, being a primitive data type has got less flexibility. We can only store the binary value of an integer in it. Since Integer is a wrapper class for int data type, it gives us more flexibility in storing, converting and manipulating an int data.

What does integer Max_value do in Java?

Integer. MAX_VALUE represents the maximum positive integer value that can be represented in 32 bits (i.e., 2147483647 ). This means that no number of type Integer that is greater than 2147483647 can exist in Java.


1 Answers

I've no idea how it's becoming negative, but starting an integer with 0 specifies it's octal (base eight). 53 in base eight is 43 in base ten.

like image 121
icktoofay Avatar answered Sep 27 '22 20:09

icktoofay