java第六次作业

 public class Test {

          /**

      * @param args

          */

         public static void main(String[] args) {

              // TODO Auto-generated method stub

           int sum = 0;

           for (int i = 1; i < 101; i++)

           {

          if (i % 10 != 3 && i != 3) {

          sum += i; }

         }

         System.out.println("和是" + sum);

 }

 }

 

 

 

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        for (int i = 1; i <5; i++) {
            for (int j = 1; j <5-i; j++) {
                System.out.print(" ");
            }
            
            for (int k = 1; k <=2*i-1; k++) {
                System.out.print("*");
            }
            System.out.println();
        }

    }

}

 

 

 

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        for (int i = 1; i < 6; i++) {            
        for (int j = 6-i; j >0; j--) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

 

 

 

import java.util.Scanner;


public class name {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入学生姓名");
        while (true) {
            String name=input.next();
            if(name.equals("Q")){
                System.out.println("程序结束");
                break;
            }    System.out.println("输入学生姓名");        
        }    
}
    }

 

 

 

import java.util.Scanner;

public class name1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入学生成绩");
        int sum = 0;
        for (int i = 0; i < 5; ) {
            System.out.println("请输入第" + (i + 1) + "个学生成绩");
            int cj = input.nextInt();
            if (cj < 0 || cj > 100) {
                System.out.println("输入错误,重新输入");
                continue;
            }i++;
            sum += cj;    
        }
        System.out.println("学生的总成绩是" + sum);
    }
}

 

 

 

package tes;

import java.util.Random;
import java.util.Scanner;

public class tes {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Random r=new Random();
        int a=r.nextInt(100);
        System.out.println(a);
      Scanner input=new Scanner(System.in);
        System.out.println("输入1-99之间数");
        int c = 0;
        while (true) {
            int b=input.nextInt();
            c++;
        if(b==a){
                System.out.println("猜对了");
                break;
        }else if(b>a) {
            System.out.println("大了点");
            continue;
        }else if (b<a) {
            System.out.println("小了点");
            continue;
        }
        } 
        
        if (c>=1&&c<=3) {
            System.out.println("太棒了");
        } else if(c>=5&&c<=8) {
            System.out.println("一般般");
        }else if(c>=5&&c<=8) {
            System.out.println("太笨了");
        }
    }

}

 

 

 

package tes;
import java.util.Scanner;

public class tes {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner input=new Scanner(System.in);
        System.out.println("输入一个数");
        int a=input.nextInt();
        boolean b=true;
        for (int i = 2; i < a-1; i++) {
            if(a%i==0){
                b=false; break;
             }        
         }
      if (b) {
          System.out.println("是质数");
          
     } else {
         System.out.println("不是质数");
  
     }
    }

}

 

 

 

package tes;
import java.util.Scanner;

public class tes {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
         int one=1;
            int two=1;
            int three=0;
             for (int i = 3; i < 21; i++) {
                three=one+two;
                one=two;
                two=three;            
            }System.out.println("第20项为:"+three);
    }

}

 

 

 

import java.util.Scanner;

 

public class name1 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

System.out.println("输入学生成绩");

int sum = 0;

for (int i = 0; i < 5; ) {

System.out.println("请输入第" + (i + 1) + "个学生成绩");

int cj = input.nextInt();

if (cj < 0 || cj > 100) {

System.out.println("输入错误,重新输入");

continue;

}i++;

sum += cj;

}

System.out.println("学生的总成绩是" + sum);

}

}

 

 

posted @ 2021-04-13 13:36  藜莂  阅读(36)  评论(0)    收藏  举报