「java模拟评分」怎么用java实现评委打分
今天给各位分享java模拟评分的知识,其中也会对怎么用java实现评委打分进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
求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; i oldScores.length; i++)
{
scores[i] = oldScores[i];
}
/** 开始排序 */
for (int i = 0; i scores.length - 1; i++)
{
k = i;
for (int j = i + 1; j scores.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; i scores.length - 1; i++)
{
num++;
sum += scores[i];
}
/** 计算平均分 */
avg = sum / num;
/** 最公平的肯定不是在scores数组两端 */
double zgp = 0;
double cha = 0;
/** 标记与平均值差值最小的分数位置 */
int flag = 0;
/** 开始寻找最公平评分 */
for (int i = 1; i scores.length - 1; i++)
{
/** 为cha赋初始值,注意比较差值要使用绝对值比较 */
if (i == 1)
{
cha = Math.abs(scores[i] - avg);
}
double cha1 = Math.abs(scores[i] - avg);
if (cha1 cha)
{
cha = cha1;
flag = i;
}
}
zgp = scores[flag];
/** 由于最不公平的分数肯定在scores数组的第一个或者是最后一个 */
double bgp = 0;
if (Math.abs(scores[0] - avg) Math.abs(scores[scores.length - 1] - avg))
{
bgp = scores[0];
}
else
{
bgp = scores[scores.length - 1];
}
/** 全部计算完成,下面开始输出结果 */
System.out.println("原始评委分数如下:");
for (int i = 0; i oldScores.length; i++)
{
System.out.print(oldScores[i] + ", ");
}
System.out.println();
System.out.println("排序后分数如下:");
for (int i = 0; i scores.length; i++)
{
System.out.print(scores[i] + ", ");
}
System.out.println();
System.out.println("去掉最高分和最低分后平均分:" + avg);
System.out.println("最公平分数:" + zgp);
System.out.println("最不公平分数:" + bgp);
}
用 java 编写一个应用程序,对数学题目进行评分
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner ipt = null;
System.out.print("输入题目数:");
ipt = new Scanner(System.in);
int count = ipt.nextInt();
System.out.println("请输入答案:");
ipt = new Scanner(System.in);
String str = ipt.nextLine();//接受输入在同一行的所有答案,保存为包括空格在内的字符串
// System.out.println(str);
String[] strs = str.split(" ");//将输入的字符串以空格为间隔分成一个字符串数组
// System.out.println("长度:"+strs.length);
//将字符串数组转成int数组,数组zqda就是保存的所有正确答案的数组
int[] zqda = new int[count];
for (int i = 0; i strs.length; i++) {
zqda[i] = Integer.parseInt(strs[i]);
}
System.out.println("请输入自己的答案:");
int[] myda = new int[count];
for (int i = 0; i myda.length; i++) {
System.out.print(i+1+".");//题号
ipt = new Scanner(System.in);
myda[i] = ipt.nextInt();
}
int yes = 0;//用来记录正确的答案
for (int i = 0; i myda.length; i++) {
if(zqda[i] == myda[i]) yes++;//如果自己的答案==标准答案,yes+1
}
System.out.println((double)yes/(double)count*100+"%");//百分数输出貌似应该还有其他简单的方法,我一时记不起来,就自己拼了一个
}
}
我也正在学习,刚好用你的例子练了一下,相互学习哈!
用java编写一个游戏级别评分器,循环录入每一局(共10局)的游戏得分,显示输出游戏级别..
方法如下,级别可以自己调整:
public class Test {
// 游戏得分总数
public static int getScore() {
int sum = 0;
for (int i = 0; i 10; i++) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第" + (i + 1) + "局的分数");
int score = scanner.nextInt();
sum += score;
}
return sum;
}
// 游戏级别
public static void getRank(int score) {
if (score = 90) {
System.out.println("总分是" + score + ":甲");
} else if (score = 70) {
System.out.println("总分是" + score + ":乙");
} else if (score = 60) {
System.out.println("总分是" + score + ":丙");
} else {
System.out.println("总分是" + score + ":丁");
}
}
// 主方法
public static void main(String[] args) {
int score = getScore();
getRank(score);
}
}
运行效果:
java模拟评分的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于怎么用java实现评委打分、java模拟评分的信息别忘了在本站进行查找喔。