public class test {
static int s
public static void main(String[] argv) {
int [] num=new int[20]
Scanner scanner=new Scanner(System.in)
Integer a
int i
for(i=1i<=20i++){
System.out.println("请输入第"+i+"一个分数(结束请输入520嘿嘿):")
a=scanner.nextInt()
num[i-1]=a
if(a==520){
break
}
}
for(int m=0m<i-1m++)
{
s=s+num[m]
}
System.out.println("总共录入了"+(i-1)+"个分数")
System.out.println("总成绩是"+s+"分")
System.out.println("平均分是"+s/(i-1)+"分")
for(Integer m=0m<num.length-1m++)
{ if(num[m]>0&&num[m]!=520){
if(num[m]>=90)
System.out.println(num[m]+"优秀")
else if(num[m]>=80)
System.out.println(num[m]+"良好")
else if(num[m]>=70)
System.out.println(num[m]+"中等")
else if(num[m]>=60)
System.out.println(num[m]+"及格")
else
System.out.println(num[m]+"不及格")
}else break
}
}
}
我的代码很简洁,采纳我呗。。。
import java.util.Scannerpublic class Test {
protected static boolean end_flag = true
public static void main(String[] args) {
Students student = new Students()
student.InputData()// 输入学生数据
String order
while (end_flag) {
System.out.println("请输入数字1-5:")
Scanner s = new Scanner(System.in)
order = s.nextLine()
student.Operator(order)
}
}
}
Students类:
import java.util.ArrayListimport java.util.Scanner
public class Students {
private int STUDENTS_NUM = 5 // 学生的人数
private int SUBJECTS_NUM = 3 // 课程数
private String[][] data = new String[STUDENTS_NUM][SUBJECTS_NUM + 2]
private String name
private int Chinese_score
private int Math_score
private int English_score
public void SearchHighestScore(String[][] original) { // 查找最高成绩
int flag = Integer.parseInt(original[0][4]), position = 0
for (int i = 1 i < original.length i++) {
if (Integer.parseInt(original[i][4]) > flag) {
flag = Integer.parseInt(original[i][4])
position = i
}
}
System.out.print("最高分同学的姓名和总分为:")
System.out.println(original[position][0] + " " + original[position][4])
}
public void SearchLowestScore(String[][] original) {
int flag = Integer.parseInt(original[0][4]), position = 0
for (int i = 1 i < original.length i++) {
if (Integer.parseInt(original[i][4]) < flag) {
flag = Integer.parseInt(original[i][4])
position = i
}
}
System.out.print("最低分同学的姓名和总分为:")
System.out.println(original[position][0] + " " + original[position][4])
}
public void OrderStudents(String[][] original) {
String[][] result = original
String temp
for (int i = 1 i < result.length i++) {
for (int j = 0 j < result.length - i j++) {
if (Integer.parseInt(result[j][4]) < Integer
.parseInt(result[j + 1][4])) {
temp = result[j][4]
result[j][4] = result[j + 1][4]
result[j + 1][4] = temp
temp = result[j][0]
result[j][0] = result[j + 1][0]
result[j + 1][0] = temp
}
}
}
System.out.println("排名\t" + "姓名\t" + "总分\t")
for (int i = 0 i < STUDENTS_NUM i++) {
System.out.println(i + 1 + "\t" + result[i][0] + "\t"
+ result[i][4])
}
}
public void ScoreUnder60(String[][] original) {
System.out.println("平均分在60以下的学生的姓名为:")
ArrayList temp = new ArrayList()
for (int i = 0 i < original.length i++) {
if (Integer.parseInt(original[i][4]) / SUBJECTS_NUM < 60) {
temp.add(original[i][0])
}
}
System.out.print(temp + " ")
System.out.println("\n" + "平均分在60以下的学生的人数为:"
+ temp.size())
}
public Integer SearchScore(String student_name) {
int position = -1
for (int i = 0 i < data.length i++) {
if (student_name.equals(data[i][0])) {
position = i
}
}
if (position != -1)
return Integer.valueOf(data[position][4])
else
return null
}
public void Operator(String order) {
if ("1".equals(order)) {
SearchHighestScore(data)
SearchLowestScore(data)
} else if ("2".equals(order)) {
OrderStudents(data)
} else if ("3".equals(order)) {
ScoreUnder60(data)
} else if ("4".equals(order)) {
String name
System.out.println("请输入学生的姓名:")
Scanner s = new Scanner(System.in)
name = s.nextLine()
if (SearchScore(name) != null)
System.out.println(name + "的总分为:" + SearchScore(name))
else
System.out.println("查无此人")
} else if ("5".equals(order)) {
Test obj = new Test()
obj.end_flag = false
System.out.println("退出")
} else {
System.out.println("输入有误!")
}
}
public void InputData() {
for (int i = 1 i <= STUDENTS_NUM i++) {
System.out.print("请输入第" + i + "个人的姓名" + ":")
Scanner s1 = new Scanner(System.in)
name = s1.nextLine()
data[i - 1][0] = name
System.out.print("请输入第" + i + "个人的语文成绩" + ":")
Scanner s2 = new Scanner(System.in)
Chinese_score = s2.nextInt()
data[i - 1][1] = String.valueOf(Chinese_score)
System.out.print("请输入第" + i + "个人的数学成绩" + ":")
Scanner s3 = new Scanner(System.in)
Math_score = s3.nextInt()
data[i - 1][2] = String.valueOf(Math_score)
System.out.print("请输入第" + i + "个人的英语成绩" + ":")
Scanner s4 = new Scanner(System.in)
English_score = s4.nextInt()
data[i - 1][3] = String.valueOf(English_score)
data[i - 1][4] = String.valueOf(Chinese_score + Math_score
+ English_score)
System.out.println(data[i - 1][4])
}
}
}
每输入一个数字判断一次
import java.util.Scannerpublic class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in)
int cj, yxsum = 0, tgsum = 0, bjgsum = 0
while ((cj = in.nextInt()) != 0) {
if (cj >= 85) {
yxsum++
} else if (cj >= 60) {
tgsum++
} else {
bjgsum++
}
}
System.out.println(yxsum)
System.out.println(tgsum)
System.out.println(bjgsum)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)