其他分享
首页 > 其他分享> > day03_fordemo

day03_fordemo

作者:互联网

package day03;

public class ForDemo {
    public static void main(String[] args) {
        /*for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0 && (i == 7 || i / 10 == 7 || i % 10 == 7)) {
                System.out.println(i);
            }
        }*/

        //自创:判断数是不是素数
        /*System.out.println("请输入一个数:");
        Scanner input = new Scanner(System.in);
        int shu=1;
        do{
            shu = input.nextInt();
            boolean f =true;
            if(shu ==0){
                break;
            }
            if(shu ==1){
                f=false;
            }
            for (int i = 2; i <shu; i++) {
                if(shu%i==0){
                    f=false;
                    break;
                }
            }
            if(f){
                System.out.println("素数");
            }else{
                System.out.println("不是素数");
            }
        }while(shu!=0);*/

        //自创:九九乘法表
        //原理:利用嵌套循环即可实现
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                //将两个数相乘的值赋值给字符串增加空格,就可以取消强迫症的不舒服感
                String str = String.valueOf(i * j);
                if (i * j < 10) {
                    str = str + " " ;
                }
                System.out.print(j + "*" + i + "=" + str + " ");
            }
            System.out.print("\n");
        }


        //自创:菱形
        //原理:利用嵌套循环,利用空格和*就可以实现
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print("  ");
            }
            for (int j = 1; j <= 2*i-1; j++) {
                System.out.print("* ");
            }
            System.out.print("\n");
        }

        for (int i = 4; i >= 1; i--) {
            for (int j = 1; j <= 5-i; j++) {
                System.out.print("  ");
            }
            for (int j = 1; j <= 2*i-1; j++) {
                System.out.print("* ");
            }
            System.out.print("\n");
        }

    }
}

标签:String,day03,fordemo,System,int,str,print,out
来源: https://blog.csdn.net/xiaoyoupei/article/details/110200337