Java中for

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37400096/article/details/83274606

1.for的应用
不知为何不能显示“*”

/*
九九乘法表
/
public class TestFor {
public static void main(String[] args) {
for(int i = 1;i<10;i++) {
for(int j = 1;j<=i;j++) {
System.out.print( i + "
" + j +
“=” + i
j+"\t");
}
System.out.println();
}
}
}
11=1
2
1=2 22=4
3
1=3 32=6 33=9
41=4 42=8 43=12 44=16
51=5 52=10 53=15 54=20 55=25
6
1=6 62=12 63=18 64=24 65=30 66=36
7
1=7 72=14 73=21 74=28 75=35 76=42 77=49
81=8 82=16 83=24 84=32 85=40 86=48 87=56 88=64
91=9 92=18 93=27 94=36 95=45 96=54 97=63 98=72 9*9=81

package dreamcoder;
/*

  • 使用for循环输出100以内的素数
    */
    public class TestFor {
    public static void main(String[] args) {
    int i,j;
    for( i = 2;i<=100;i++) {
    int k =(int) Math.sqrt(i);
    for(j = 2;j<=k;j++) {
    if( i % j == 0 ) {
    break;
    }
    }
    if(j > k) {
    System.out.println( i + " " + “is a prime”);
    }
    }
    }
    }

猜你喜欢

转载自blog.csdn.net/qq_37400096/article/details/83274606