编辑代码

package rj2201;

import java.util.Scanner;

public class 猜数 {
    public static void main(String[] args) {
        int sjs=(int)(Math.random()*20)+1;
        int cs=1;
        boolean flag=true;
        while(cs<5){
            System.out.println("请输入一个整数:");
            Scanner sc=new Scanner(System.in);
            int caideshu=sc.nextInt();
            if(caideshu==sjs){
                System.out.println("恭喜猜对了!");
                flag=false;
                break;
            } else if(caideshu>sjs){
                System.out.println("猜大了!");
            }else if(caideshu<sjs){
                System.out.println("猜小了");
            }else
                System.out.println("请继续猜");
            cs++;
        }
        if(flag==true)
            System.out.println("很遗憾,您5次都没猜中");
    }
}