编辑代码

import java.util.Scanner;
// public class Demo1{
//     public static void main(String[] args){
//         Scanner input = new Scanner(System.in);
//         System.out.println("输入星星行数");
//         int count = input.nextInt();
//         for(int i=1; i<=count; i++){//控制行数
//                 //第一行规则
//             //   i=1 7 0    count=4 7 count=5 9
//             //   i=2 3 1 3
//             //   i=3 2 3 2
//             //   i=4 1 5 1
//                  if(i==1){//画星星
//                     for(int j=1; j<=2*count-1; j++){
//                         System.out.print("*");
//                     }
                    
//                 }else{//后面几行规则
//                       //画左边的星星
//                     for(int j=1; j<=(count+1)-i; j++){
//                         System.out.print("*");
//                     }
//                      //画空格
//                     for(int j=1; j<=2*i-3; j++){
//                         System.out.print(" ");
//                     }
//                     //画星星
//                     for(int j=1; j<=(count+1)-i; j++){
//                          System.out.print("*");
//                     }
//                 }                 
//             System.out.println();
//         }      
           
                
//     }
// }

// public class Demo2{
//     public static void main(String[] args){
//             for(int i=1; i<=4; i++){//控制行数
//             //空格占位
//                 for(int j=1; j<=4-i; j++){
//                     System.out.print(" ");
//                 }
//             //左边的数字--利用循环里层的变量j来控制 j++
//                 for(int j=1; j<=i; j++){
//                     System.out.print(j);
//                 }
//             //右边的数字--利用循环里层的变量j来控制 j--
//                 for(int j=i-1; j>=1; j--){
//                    System.out.print(j); 
//                 }
//             //换行
//             System.out.println();
//             }          
            
           
//     }
// }

// public class Demo3{
//     public static void main(String[] args){
//         //打印输出9*9乘法表
//         //1*1=1
//         //1*2=2 2*2=4
//         //1*3=3 2*3=6 3*3=9
//         //在一行之中 被乘数发生变化j 乘数固定i
//             for(int i=1; i<=9; i++){//控制行数
//             //画表达式
//                 for(int j=1; j<=i; j++){ //控制每一行表达式的个数
                    
//                     System.out.print(j+"*"+i+"="+(i*j)+"\t");//字符串拼接
//                 }//换行
//             System.out.println();       
//             }                
//         }
// }

public class Demo4{
    public static void main(String[] args){
        //2-100之间的素数 每一个数字做一个输出
        for(int num=2; num<=100; num++){ //先把1和本身这两个数字 刨除掉
            boolean x = false;//标识干净的裤子
            for(int i=2; i<num/2; i++){
                if(num%i==0){//在剩下的数字中挨个找寻一遍 看一看还有没有其他的整除数字  
                    System.out.println(num+"不是素数");
                    x = true; //相当于标识修改了
                    break; //不是中断if 当满足条件的时候中断循环
                }
            }
            if(x==false){
                 System.out.println(num+"是素数");//是素数
            }
        }
     
       
         
        
              
        
       
                
           
        
        
     }
        
    }