用JAVA程序编写:输入10个学生的成绩,分数由高到低排序
发布网友
发布时间:2022-06-19 10:35
我来回答
共3个回答
热心网友
时间:2024-12-04 07:10
package test;
import java.util.Scanner;
public class test{
public static void main(String[] args)
{
test ts = new test();
Scanner sc = new Scanner(System.in); //Scanner类的构造方法。
int a[] = new int[10];
System.out.println("输入10个同学的成绩,中间以空格隔开");
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt(); //依次输入数字中间以空格隔开。
}
test.maopao(a); //调用排序方法。
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
}
public static void maopao(int array[]) { //定义冒泡排序方法。
int i;
int k;
for (i = 0; i < array.length; i++) {
for (k = 0; k < array.length - 1 - i; k++) {
if (array[k] < array[k + 1]) {
int temp = array[k];
array[k] = array[k + 1];
array[k + 1] = temp;
}
}
}
}
}
热心网友
时间:2024-12-04 07:10
package
a;
import
java.io.bufferedreader;
import
java.io.inputstreamreader;
import
java.util.arrays;
import
java.util.comparator;
public
class
test1
{
class
score{
string
name;
float
score1;
float
score2;
float
score3;
float
scorea;
score(string
name,
string
s1,
string
s2,
string
s3){
this.name
=
name;
score1
=
float.parsefloat(s1);
score2
=
float.parsefloat(s2);
score3
=
float.parsefloat(s3);
scorea
=
(score1
+
score2
+
score3)/3;
}
public
string
tostring(){
return
name
+
"\t"
+
score1
+
","
+
score2
+
","
+
score3;
}
}
public
static
void
main(string[]
args)
throws
exception{
final
int
num
=
3;
test1
t
=
new
test1();
system.out.println("请依次输入姓名,数学,英语,计算机的成绩,用回车分割");
score[]
arr
=
new
score[num];
bufferedreader
in
=
new
bufferedreader(new
inputstreamreader(system.in));
for
(int
i=0;i
(){
public
int
compare(score
s1,
score
s2)
{
if
(s1.scorea
<
s2.scorea)
return
-1;
if
(s1.scorea
>
s2.scorea)
return
1;
if
(s1.score1
<
s2.score1)
return
-1;
if
(s1.score1
>
s2.score1)
return
1;
if
(s1.score2
<
s2.score2)
return
-1;
if
(s1.score2
>
s2.score2)
return
1;
if
(s1.score3
<
s2.score3)
return
-1;
if
(s1.score3
>
s2.score3)
return
1;
return
0;
}
});
for
(int
i=0;i
评论
0
0
加载更多
热心网友
时间:2024-12-04 07:11
输入有没有什么*,是提示输入,还是运行程序时直接输入