Given the following code fragment:
public class Calc {
public static void main (String [] args) {
//* insert code here Line **
System.out.print("The decimal value is" + var);
}
Which three code fragments, when inserted independently at line **, enable the code to compile/
A.
int var = 0b_1001;
B.
long var = 0b100_01L;
C.
float var = 0b10_01;
D.
float var = 0b10_01F;
E.
double var = 0b10_01;
F.
double var = 0b10_01D;
Explanation:
B: output 17
C: output 9.0
E: output 9.0
Not A: A _ character cannot begin a number.
Not D: A float cannot be defined as a binary number (with literal B)
Not F: A float cannot be defined as a decimal number (with literal D)
Note1:
In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between
digits in a numerical literal. This feature enables you, for example. to separate groups of digits in
numeric literals, which can improve the readability of your code.
For instance, if your code contains numbers with many digits, you can use an underscore
character to separate digits in groups of three, similar to how you would use a punctuation mark
like a comma, or a space, as a separator.
You can place underscores only between digits; you cannot place underscores in the following
places:
* At the beginning or end of a number (not A)
* Adjacent to a decimal point in a floating point literal
* Prior to an F or L suffix
* In positions where a string of digits is expected
Note 2:An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is
recommended that you use the upper case letter L because the lower case letter l is hard to
distinguish from the digit 1.
Values of the integral types byte, short, int, and long can be created from int literals. Values of type
long that exceed the range of int can be created from long literals. Integer literals can be
expressed by these number systems:
Decimal: Base 10, whose digits consists of the numbers 0 through 9; this is the number system
you use every day
Hexadecimal: Base 16, whose digits consist of the numbers 0 through 9 and the letters A through F
Binary: Base 2, whose digits consists of the numbers 0 and 1 (you can create binary literals in
Java SE 7 and later)
Reference: The Java Tutorials,Primitive Data Types:
Using Underscore Characters in Numeric Literals
Integer Literals
B,C,E