求质�?

/*
需求:键盘录入一个正整数,判断该整数是否为质�?
*/

import java.util.Scanner;

public class itheima_p51 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入你想判断的数�?:");
        int number = sc.nextInt();
        boolean flag = true;
        for (int i = 2; i < number - 1; i++) {
            if(number % i == 0){
                flag = false;
                break;
            }
        }
        if(flag=true){
            System.out.println("该数字为质数");
        }else{
            System.out.println("该数字不为质�?");
        }
    }
}

猜数字小游戏

/*
需求:程序随机生成一�?1-100之间的随机数字,使用程序实现猜出这个数字是多�?
要求:最大猜测次数为10,如�?5次猜不出,则结束本次猜测�?
*/
import java.util.Random;
import java.util.Scanner;

public class itheima_p51 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random in = new Random();
        int flag = 0;
        int number = in.nextInt(100) + 1;
        while(true){
            System.out.println("请输入你想猜的数�?");
            int a = sc.nextInt();
            if(flag == 5){
                System.out.println("您的次数已用�?");
                break;
            }
            else if(a > number){
                System.out.println("大了");
                flag++;
                continue;
            }
            else if(a < number){
                System.out.println("小了");
                flag++;
                continue;
            }else{
                System.out.println("猜对�?");
                break;
            }
        }
    }
}