Scanner输入
Scanner sc = new Scanner(System.in);
Double a = sc.nextDouble();
String str = sc.nextLine();
随机数
int a = (int)(Math.random*6)+1;
random方法会自动生成0-1(不包括1)的任意数字,乘6就会生成0-6(不包括6),再强制取整得到0-5的数字,最后加一就可以得到1-6
switch语句
switch(表达式){
case 值1:
语句一;
break;
case 值2:
语句二;
break;
default:
默认语句;
break;
}
其中表达式中不能是long类型
带标签的continue语句
//打印101-150中的质数
here: for (int i = 101; i <151 ; i++) {
for (int j = 2; j < i>>2; j++) {
if (i%j==0) {
continue here;
}
}
System.out.print(i+" ");
}
唯一可以用的地方
方法参数
- 形式参数——方法定义时
- 实体参数——方法调用时
面向对象中整个程序的基本单位是类