记录有一定的c++基础向java学习的过渡
import java.math.BigInteger;
import java.sql.SQLOutput;
public class Main {
public static void main(String[] args) {
byte by=-128;//java还有byte类型,一个字节
final int a=9;//java的常量用final
long b=3000000000l;//long类型后边的变量要加l或者L,(超过int时)
BigInteger c=new BigInteger("12000000000000000000000");//数值过大创建BigInteger对象
//BigDecimal 进行高精度计算
int d=100_00_00;//加_没啥影响,方便看数
String str="ELDEN RING";//字符串,不是基本类型,java中的一个类
char ch='好';//java内的char为2字节
boolean flag=true;//java的布尔类型
int e=128;
byte f=(byte) e;
f= (byte) (e+1);//因为计算时e被自动转换为int所以计算的返回值与接收类型不匹配,强转后才能被赋给f
/*
* 类型自动装换时向上对齐,如:
* long和float计算,均被转成float再计算
* 另外,在计算时无论是否有更大的类型,byte,char,short均被转成int,有大类型就还是向上对齐
* */
short p=90;
double x=12.8;
/*int m;
m=p+x; 报错*/
System.out.println(p+x);
System.out.println("hello world!");
System.out.println(by);
System.out.println(b);
System.out.println(a);
System.out.println(c);
System.out.println(d);
System.out.println(str);
System.out.println((short) ch );
System.out.println(f);
System.out.print(f);//不会自动换行
System.out.println();
int g=10;
int h=2;
System.out.println(g+++h++);
/*
* java中+天生就可以连接字符串
* 加号也能让字符串与其类型连接,但其他的类型也被看成字符串
* */
byte s=3;
System.out.println("DARK"+" "+"SOULS");
System.out.println("DARK"+" "+"SOULS"+s);
}
}
![]()