package work02;
/*
*定义八种不同数据类型的变量,赋值并输出到控制台。
-
*/
public class test {public static void main(String[] args) {
//定义字节型变量
byte b1 = -128, b2 = 127;
// 调用系统 System类的out对象的print()方法,输出字符串和变量的值
System.out.println("byte b1 = " + b1 ); // '\n' 字符常量表示换行
System.out.println("byte b2 = " + b2 );//定义短整型变量 short s1 = -32768,s2 = 32767; System.out.println("short int s1 = " + s1 ); System.out.println("short int s2 = " + s2 ); //定义整型变量 int i1 = -2147483648,i2 = 2147483647; System.out.println("int i1 = " + i1 ); System.out.println("int i2 = " + i2 ); //定义长整型变量 long l = 123456789L; System.out.println("long int l = " + l ); //定义单精度类型变量(浮点数即带有小数点的数) float f = 3.14159F; System.out.println("float f = " + f ); //定义双精度类型变量(浮点数即带有小数点的数) double d = 3.14; System.out.println("double d = " + d ); //定义字符型变量 char c1 = 'c', c2 = '国', c3 = 'Y' ; System.out.println("char c1+c2+c3 = " + c1 + c2 + c3 ); //定义布尔型变量 boolean flag = true ; System.out.print("boolean flag is " + flag); }
}