|
|
Исходный текст программы BaseType.java
|
Оглавление |
Назад
// ==========================================
// BaseType.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
public class BaseTypes
{
public static void main(String args[])
{
// -----------------------------------
// boolean
// -----------------------------------
System.out.println("* boolean *\n");
boolean fBooleanValue = true;
if(fBooleanValue)
{
System.out.println(
"Set fBooleanValue to 'false'");
fBooleanValue = false;
System.out.println("fBooleanValue = "
+ fBooleanValue);
// ERROR: Incompatible Type.
// Can't convert boolean to int
// int i = fBooleanValue;
}
// -----------------------------------
// byte
// -----------------------------------
System.out.println("\n* byte *\n");
byte bByteValue = 126;
bByteValue += 1;
System.out.println("bByteValue = "
+ bByteValue);
bByteValue += 1;
System.out.println("bByteValue = "
+ bByteValue);
// -----------------------------------
// char
// -----------------------------------
System.out.println("\n* char *\n");
char chCharValue = '*';
System.out.println("chCharValue = "
+ chCharValue);
chCharValue += 1;
System.out.println("chCharValue = "
+ chCharValue);
chCharValue = 0x0455;
System.out.println("chCharValue = "
+ chCharValue);
// -----------------------------------
// short
// -----------------------------------
System.out.println("\n* short *\n");
short shShortValue = 32767;
System.out.println("shShortValue = "
+ shShortValue);
shShortValue +=2;
System.out.println("shShortValue = "
+ shShortValue);
shShortValue = (short)chCharValue;
System.out.println("Value of chCharValue = "
+ shShortValue);
// -----------------------------------
// int
// -----------------------------------
System.out.println("\n* int *\n");
int iIntValue = 2147483647;
System.out.println("iIntValue = "
+ iIntValue);
iIntValue += 2;
System.out.println("iIntValue = "
+ iIntValue);
// -----------------------------------
// long
// -----------------------------------
System.out.println("\n* long *\n");
long lLongValue = 9223372036854775807L;
System.out.println("lLongValue = "
+ lLongValue);
lLongValue += 1;
System.out.println("lLongValue = "
+ lLongValue);
// -----------------------------------
// float
// -----------------------------------
System.out.println("\n* float *\n");
float flFloatValue = 526e-3F;
System.out.println("flFloatValue = "
+ flFloatValue);
flFloatValue /= 3;
System.out.println("flFloatValue = "
+ flFloatValue);
// -----------------------------------
// double
// -----------------------------------
System.out.println("\n* double *\n");
double dblDoubleValue = 526E-3D;
System.out.println("dblDoubleValue = "
+ dblDoubleValue);
dblDoubleValue /= 3;
System.out.println("dblDoubleValue = "
+ dblDoubleValue);
}
}
|
|
|