import static java.lang.Math.* //导入Math这个包,就不用再常量名前加前缀
class I {
public static void main(String[] agrs){
int m = 7;
int n = 7;
int a = 2 * ++m; //a等于16。m等于8;m先加1 再*2
int b = 2 * n++; //b等于14,n等于8;n先*2再+1
System.out.println(a);
System.out.println(b);
System.out.println(n);
System.out.println(m);
if (n == m) { //==检测是否相等
System.out.println(true);
}
if (a != b) { //!=检测是否不相等
System.out.println(false);
}
b < a ? b:a //返回ab中较小的值。
double x = 4;
double y = Math.sqrt(x); //计算数值的平方根用sqrt方法
System.out,println(y);//prints 2.0
double y =Math.pow(x,a); //将y的值设置为x的a次幂
/**
常用的三角函数
*/
Math.sin
Math.cos
Math.tan
Math.atan
Math.atan2
/**
自然对数
*/
Math.exp
Math.log
}
}
int n = 123456789;
float f = n; // f == 1.234567892E8,先换成同种类型再计算
double x = 9.997;
int nx = (int)x;//变量n的值变为9,强制类型转换通过截断小数部分将浮点值转换成整型
double x = 9.997;
int nx = (int) Math.round(x);//变量n的值为10;使用round方法需要转换成int类型
a&&b||c //&&的运算级比||高相当于(a&&b)||c
a+=b+=c 等于a+=(b+=c);//右结合运算,先b+c后在+a
enum Size{SMALL,MEDIUM,LARGE,EXTRA_LSG/RGE};//枚举类型也可以这样声明 Size s = Size.MEDOIM;
String e = "";
String greeting = "Hello";//String字符串
String greeting = "Hello";
String s = greeting.substring(0,3);//创建了一个由“Hel”组成的字符串
String expletive = "Expletive";
String PG13 = "deleted";
String message = expletive + PG13; //使用+号连接两个字符串,当字符串与非字符串连接时非字符串被转换成字符串再连接
greeting = greeting.substring(0,3) + "p!";//将上条语句的值改为Hellp!,不可变的字符串