boolean flag = true;
- System.out.println("hello" + 100 + 3);// 输出hello1003
- System.out.println(100 + 3 + "hello"); //输出103hello
- 浮点数=符号位+指数位+尾数位
- 错误写法:float num2 = 1.1; 正确写法:double num3 = 1.1f;
- double num = 8.1 / 3 != 2.7 (2.66666667)
if(Math.abs(num1 - num2) < 0.000001) {
System.out.println("相等");
}
boolean flag = true;
·bool类型只能是true / false 不能是0 或 1(和c语言不同)
基本类型转String
String str = n1 + "";
String 转 int
String s = “123”
int num1 = Integer.parseInt(s5);//字符串转int
程序中+号的使用
System.out.println(100 + 3 + "hello");//103hello
System.out.println("hello" + 100 + 3);//hello1003
键盘输入:
import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
int age = myScanner.nextInt();
String name = myScanner.next();
System.out.println(age + name);
}
}
计算机运算以补码形式实现
取第一个字符:
char c1 = myScanner.next().charAt(0);
switch case
switch( ){
case _ : ....;
break;
default : ...;
}
Math.random()随机选取大于0.0小于1.0的double值
System.out.println((int)(Math.random() * 100);
String name = "lc";
System.out.println("lc".equals(name));
int hens[] = new int[5];
for(int i = 0; i < hens.length; i++)
hens[i] = myScanner.nextInt();
列举A - Z
chars[i] = (char)('A' + i); //需要强制转换
int arr1[] = {1, 2, 3};
int arr2[] = arr1;
若改变arr1[1]的值,arr2[1]的值也会随之改变