制表符的使用
public class Demo1 {
public static void main(String[]args) { //main主函数
// \t为制表符,可以把打印的字符补齐到4的倍数位,来达到对齐的要求
System.out.println("wangwu" + "lisi");//+表示为联合打印
System.out.println("25" + "26");
//使用 \t后
System.out.println("wangwu" + '\t' + "lisi");
System.out.println("25" + '\t' + "26");
//变量
int a = 2003;//int为整数
double b = 6.66;//double为小数
System.out.println(a);
System.out.println(b);
/*定义变量时直接赋值
int c;
c = 66;与(int = 66;)一致
*/
int c = 66;
System.out.println(c);
//重新赋值
c = 50;
System.out.println(a + c);
System.out.println(a + b);
}
}
各数据类型的使用
public class Demo2 {
public static void main(String[] args){
//各字符长度,超过字符范围报错
//所有之间的大小 double>float>long>int>short>byte
byte a = 50;//字符长度(-128<a<127)
System.out.println(a);
short b = 60;//字符长度(-32768<b<32767)
System.out.println(b);
int c = 700;//字符长度(-21亿<c<21亿)亿=10位数;int为默认使用
System.out.println(c);
//Long定义变量在数值最后加一个大写的L
long d = 800000;//字符长度(-19位数<d<19位数)
System.out.println(d);
Long e = 800000L;
System.out.println(e);
//当使用小数时,float范围较小
float f = 2.5f;//使用float定义变量时,需要在结尾加上(f)
System.out.println(f);//(-3.4e-38<f<3.4e+38)
double g = 20.5;//double为默认使用
System.out.println(g);
char h = '男';
System.out.println(h);
/*char i = "字符串";
System.out.println(i);不能这么打印
char h = "abs";
System.out.println(h);也不能这么打印*/
}
}