package HelloWorld1;
public class YinShiZhuanHuan {
public static void main(String[] args) {
byte a=100; // byte类型的范围是-128~127
short b=30000;// short 范围是-32768~32767
char s=10000;// char 表示一个字符如“a","A","0","你”
boolean x=true;// java里面的true所有字符小写,python里面首字母要大写
//byte,short,char,默认转换成int(-2147483648~2147483648)<long<float<double
boolean y=false;//
System.out.println(a+b+s);//java 中字符串也可以和数字直接相加,而python中是不可以的
System.out.println(x);
System.out.println(y);
}
}
运行结果:
40100
true
false
package HelloWorld1;
public class YinShiZhuanHuan {
public static void main(String[] args) {
byte a=100; // byte类型的范围是-128~127
short b=30000;// short 范围是-32768~32767
char s=10000;// char 表示一个字符如“a","A","0","你”
boolean x=true;// java里面的true所有字符小写,python里面首字母要大写
boolean y=false;//
byte a1=25;
short a2=10000;
short a3=a1+a2;
System.out.println(a+b+s);//java 中字符串也可以和数字直接相加,而python中是不可以的
System.out.println(x);
System.out.println(y);
//System.out.println(a1+a2);
System.out.println(a3);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from int to short
at HelloWorld1.YinShiZhuanHuan.main(YinShiZhuanHuan.java:12)
byte,short,char之间计算的时候如果print(a+b)
java会根据计算数值的大小自行转换成int,long,float,double
如果强制定义short c=a+b print© 那么就会报错,因为int,long,float,double 不可以转换成byte,short,char