This question already has answers here:
Why are integer literals with leading zeroes interpreted strangely?
(8 answers)
Java int zero prefix? [duplicate]
(2 answers)
Closed 8 years ago.
why output so strange 0022 =18?
hello everyone to day i have test.the question is "what is the output of
System.out.println(0022);
i so confuse why Answer is 18
explain needed
If the first digit of an int literal is 0, Java interprets the number in octal (base 8).
Related
This question already has answers here:
How to check if an integer can be divided by 3
(8 answers)
Check division by 3 with binary operations?
(2 answers)
How to know if a binary number divides by 3?
(3 answers)
Closed 4 days ago.
How to check whether a number divisible by 3 using bit manipulation
can anyone tell me how to do it in java
This question already has answers here:
Converting an int to a binary string representation in Java?
(19 answers)
Closed 3 years ago.
Let's say i have a binary number initialized like this:
int y=0b110101;
How could i convert 110101 to a String?
I would like this:
String str1 = Integer.toString(y);
System.out.println(str1);
to give result 110101 or 0b110101 and not 53.
Integer.toBinaryString(y) would give you 110101 in your case and you can prepend the 0b to the result if you'd like that.
This question already has answers here:
Why is 08 not a valid integer literal in Java?
(6 answers)
Closed 4 years ago.
int a=019;
int b;
b=a;
System.out.println(a);
Main.java:13: error: integer number too large: 019
int a=019;
^
1 error
Integer literals beginning with a "0" are treated as octal. The permissible digits are 0 through 7.
Hexadecimal literals begin with 0x, e.g. 0xA
This question already has answers here:
Why is 08 not a valid integer literal in Java?
(6 answers)
Closed 4 years ago.
when put 08 in array then it shows a error "The literal 08 of type int is out of range"
Integer literals starting with 0 in Java are parsed as octal, and 0-7 are the only valid octal digits.
This question already has answers here:
Scala Doubles, and Precision
(15 answers)
Java BigDecimal: Round to the nearest whole value
(7 answers)
Closed 7 years ago.
What is the best solution to make my BigDecimal to have 2 digits after the decimal point (while keeping it as precise as possible) in Scala?
val bigDec1 = BigDecimal(12345.12)
val bigDec2 = BigDecimal(1345.12)
((bigDec1/bigDec2)*100)
The last row is equal to 917.7709051980492446770548352563340 but I want it to be 917.77.