Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

Question about primitive variable types in Java?

I have a question about primitive variable types. How come whenever I declare a long variable, I have to put an "l" at the end of the value or else I get a compiler error saying "integer number too large."? It also happens with doubles, too.

And I have another question about "double" variable types. How come the Java documentation thing lists them as being able to hold values from "8 bytes IEEE 754. Covers a range from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative)." But when I put in a higher value, even something (relatively) small like two billion won't fit unless I put a "d" at the end of the value. Why is this? And what does the "-324d" and "+308d" thing mean? Is this scientific notation or is that the decimal precision of the "double" variable type? Thanks.

2 Antworten

Relevanz
  • vor 1 Jahrzehnt
    Beste Antwort

    The l and the d tell the compiler that it should treat the preceding value as a long integer or double floating point, respectively.

    The +308 and -324 represent powers. The 'E' separates the significand (4.94065645841246544 in the first case) from the exponent.

  • vor 1 Jahrzehnt

    Java supplies four different primitive integer data types whose characteristics are

    type size

    byte 8

    short 16

    int 32

    long 64

    Lets talk about int and long

    int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead.

    long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.

    int size is 32 bit while Long size is 64 bit

    to show the difference between int and long it is need to put 'L' at the end of long integer

    Now if you use any ineger in your program whose maximum value is greater than 2,147,483,647. This means your ineger becomes now Long. to show your integer is Long you have to

    to put 'L'

    if you don't use 'L' java compiler considered as int and

    give you error becausee size is passing it's limit of int and enters in Long so you have to put 'L'

    0

    -128

    +127

    short

    16

    0

    -32768

    +32767

    int

    32

    0

    -2147483648

    +2147483647

    long

    64

    size(bits)

    default value

    minimum value

    maximum value

Haben Sie noch Fragen? Jetzt beantworten lassen.