4.循环结构
public class Circulate {
public static void main(String[] args) {
//while 循环
int i = 0;
//只要满足i<10,里面的内容就会一直执行
System.out.println("while循环");
while(i < 10){
System.out.print(i+" ");
i++;
}
//do while循环
System.out.println("");
System.out.println("do while循环");
i = 0;
//满足i<10,里面的内容也会执行,与上面不同的是do while至少会执行一次
do{
System.out.print(i+" ");
i++;
}while(i<10);
//for循环,初始条件是i=0,只要i<10,就执行里面的语句,语句执行完了,i++
System.out.println("");
System.out.println("for循环");
for(i=0;i<10;i++){
System.out.print(i+" ");
}
//嵌套循环
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
System.out.println("j为"+j+",k为"+k);
}
}
//continue,跳过这一次循环,进行下一次循环
for(int j=0;j<100;j++) {
if (j % 7 == 0) {
continue;
}//j为7的倍数的时候不打印
System.out.print(j+" ");
}
System.out.println("");
//break,终止循环
for(int j=0;j<100;j++) {
if (j == 7) {
break;
}//j为7的时候,终止循环
System.out.print(j+" ");
}
System.out.println("");
}
}
5.Math库
public class MathUse {
public static void main(String[] args) {
System.out.println("90度的正弦值:" + Math.sin(Math.PI/2));
System.out.println("0度的余弦值:" + Math.cos(0));
System.out.println("60度的正切值:" + Math.tan(Math.PI/3));
System.out.println("1的反正切值: " + Math.atan(1));
System.out.println("π/2的角度值:" + Math.toDegrees(Math.PI/2));
System.out.println("π的值:"+Math.PI);
System.out.println("-1的绝对值:"+ Math.abs(-1));
System.out.println("1.5取整的值:"+Math.floor(1.5));
System.out.println("1.5四舍五入的值:"+Math.round(1.5));
System.out.println("1.5取上面的整的值:"+Math.ceil(1.5));
System.out.println("2的三次方的值:"+Math.pow(2,3));
System.out.println("ln2的值:"+Math.log(2));
System.out.println("lg2的值:"+Math.log10(2));
System.out.println("根号2的值:"+Math.sqrt(2));
System.out.println("e的立方:"+Math.exp(3));
System.out.println("3、4中的较大值"+Math.max(3,4));
System.out.println("3、4中的较小值"+Math.min(3,4));
}
}
5.5作业
- 求方程19x+93y=4xy的整数解, -1000<x,y<1000
- 求回归直线