Java代码评语 java 优秀代码

java计算机产生随机数,猜中即胜,猜不中,提示是大了还是小了,继续猜,直至猜到,给出所用时间和评语 。猜数小游戏代码如下,请参照:
/**
* 猜数小游戏
*
*/
public class xxx {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = (int) (Math.random() * 100); // 产生随机数
int guess;// 用户猜的数字
int count = 0;// 猜测次数
System.out.println("我心里有一个0到99之间的整数,你猜是什么?");
long starttime=System.currentTimeMillis();
// 用户猜测随机数
do {
guess = input.nextInt();
if (numberguess) {
System.out.println("大了点,再猜!");
count++;
} else if (numberguess) {
System.out.println("小了点,再猜!");
count++;
} else {
count++;
break;
}
} while (true);
long endtime=System.currentTimeMillis();
System.out.println("这个数字是"+number);
System.out.println("您猜的次数是"+count);
System.out.println("您猜的时间是"+((endtime-starttime)/1000/60)+"秒");
// 根据猜测次数给出评价
if (count == 1) {
System.out.println("你太聪明了!");
} else if (count = 2count = 5) {
System.out.println("不错,再接再厉!");
} else {
System.out.println("要努力?。?);
}
}
}
运行如下:
求JAVA评委打分代码正好我闲着,给你写一个吧 。
我写的这个评委分数是在代码里固定到数组里了,如果你需要运行时手动输入评分,可以将oldScores里的数据改成手动输入就行了(这个不用我再写了吧,如果不会再追问 , 再告诉你) 。
你先新建一个类,将下面的main方法全部复制进去就能运行了 , 自己看一下吧 。
/** 主方法 */
public static void main(String[] args)
{
/** 保存原始评分的数组(如果你需要运行时手动输入分数 , 将 oldScores中的数据改成手动输入就行了 */
double[] oldScores = {15, 77, 55, 88, 79, 98, 67, 89, 68, 88};
/** 最终将用来保存排序后的数组 */
double[] scores = new double[oldScores.length];
double temp;
/** 平均分 */
double avg = 0;
int k;
/** 将原始评分放入最终排序数组 */
for (int i = 0; ioldScores.length; i++)
{
scores[i] = oldScores[i];
}
/** 开始排序 */
for (int i = 0; iscores.length - 1; i++)
{
k = i;
for (int j = i + 1; jscores.length; j++)
{
if (scores[k]scores[j])
{
k = j;
}
}
if (i != k)
{
temp = scores[k];
scores[k] = scores[i];
scores[i] = temp;
}
}
/** 计算去掉最高分和最低分之后的和 */
double sum = 0;
/** 记录计算平均分的分数个数 */
double num = 0;
for (int i = 1; iscores.length - 1; i++)
{
num++;
sum += scores[i];
}
/** 计算平均分 */
avg = sum / num;
/** 最公平的肯定不是在scores数组两端 */
double zgp = 0;
double cha = 0;
/** 标记与平均值差值最小的分数位置 */
int flag = 0;
/** 开始寻找最公平评分 */
for (int i = 1; iscores.length - 1; i++)
{
/** 为cha赋初始值,注意比较差值要使用绝对值比较 */
if (i == 1)
{
cha = Math.abs(scores[i] - avg);
}
double cha1 = Math.abs(scores[i] - avg);
if (cha1cha)
{
cha = cha1;
flag = i;
}
}
zgp = scores[flag];
/** 由于最不公平的分数肯定在scores数组的第一个或者是最后一个 */
double bgp = 0;
if (Math.abs(scores[0] - avg)Math.abs(scores[scores.length - 1] - avg))

推荐阅读