mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 18:24:39 +02:00
up
This commit is contained in:
@@ -36,38 +36,23 @@ System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true);
|
|||||||
// Types
|
// Types
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
// You have to declare variables before using them. A variable declaration
|
// Byte - 8-bit signed two's complement integer (-128 <= byte <= 127)
|
||||||
// requires you to specify its type; a variable's type determines its size
|
|
||||||
// in bytes.
|
|
||||||
|
|
||||||
// Integers
|
// Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767)
|
||||||
int x_int = 0;
|
|
||||||
|
|
||||||
// shorts are usually 2 bytes
|
//Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647)
|
||||||
short x_short = 0;
|
int x = 1;
|
||||||
|
|
||||||
// chars are guaranteed to be 1 byte
|
//Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
|
||||||
char x_char = 0;
|
|
||||||
char y_char = 'y'; // Char literals are quoted with ''
|
|
||||||
|
|
||||||
// longs are often 4 to 8 bytes; long longs are guaranteed to be at least
|
//Float - Single-precision 32-bit IEEE 754 Floating Point
|
||||||
// 64 bits
|
|
||||||
long x_long = 0;
|
|
||||||
long long x_long_long = 0;
|
|
||||||
|
|
||||||
// floats are usually 32-bit floating point numbers
|
//Double - Double-precision 64-bit IEEE 754 Floating Point
|
||||||
float x_float = 0.0;
|
|
||||||
|
|
||||||
// doubles are usually 64-bit floating-point numbers
|
//Boolean - True & False
|
||||||
double x_double = 0.0;
|
|
||||||
|
//Char - A single 16-bit Unicode character
|
||||||
|
|
||||||
// Integral types may be unsigned. This means they can't be negative, but
|
|
||||||
// the maximum value of an unsigned variable is greater than the maximum
|
|
||||||
// value of the same size.
|
|
||||||
unsigned char ux_char;
|
|
||||||
unsigned short ux_short;
|
|
||||||
unsigned int ux_int;
|
|
||||||
unsigned long long ux_long_long;
|
|
||||||
|
|
||||||
// Other than char, which is always 1 byte, these types vary in size depending
|
// Other than char, which is always 1 byte, these types vary in size depending
|
||||||
// on your machine. sizeof(T) gives you the size of a variable with type T in
|
// on your machine. sizeof(T) gives you the size of a variable with type T in
|
||||||
|
Reference in New Issue
Block a user