猜数字

来源:互联网 发布:vscode 插件推荐 编辑:程序博客网 时间:2024/06/09 17:18
import java.util.Scanner;


import com.sxt.oop.school;


/**
 * @author Rory
 * @category 猜数 1到100内猜数
 */
public class Caishu {


int a = (int) (Math.random() * 100);
int s;


public void Cai() {
System.out.println("请输入你猜的数字");
Scanner sc = new Scanner(System.in);
s = sc.nextInt();
//return s;
}


public void Check() {
boolean flag = true;
do {
if (s == a) {
System.out.println("恭喜你,猜对了");
System.exit(0);
}
if (s > a) {
System.out.println("大了");
} else {
System.out.println("小了");
}
Cai();
} while (flag);
}

}


/**
 * @author Administrator
 * @category 猜数测试
 */
public class CaishuTest {


public static void main(String[] args) {

Caishu shu=new Caishu();
shu.Cai();
shu.Check();
}


}

0 0
原创粉丝点击