编写一个程序,提示用户输入学生个数,学生学号和他们的课程成绩,然后按照学生成绩的降序打印学生的学号.

编写一个程序,提示用户输入学生个数,学生姓名和他们的成绩,然后按照学生成绩的降序打印学生成绩的排行榜.~

import java.util.Arrays;
import java.util.Scanner;

public class Test {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("请输入学生个数");
String strStuNum = reader.nextLine();
int stuNum = Integer.parseInt(strStuNum);
String[] sNames = new String[stuNum];
int[] sScore = new int[stuNum];
for(int i = 0;i < stuNum; i++){
System.out.println("请输入第"+(i+1)+"个学生的姓名");
sNames[i] = reader.nextLine();
System.out.println("请输入"+sNames[i]+"的分数");
sScore[i] = Integer.parseInt(reader.nextLine());
}
int tempScore;
String tempName;
for (int i = stuNum - 1; i > 0; --i) {
boolean isSort=false;
for (int j = 0; j < i; ++j) {
if (sScore[j + 1] < sScore[j]) {
tempScore = sScore[j];
tempName = sNames[j];
sScore[j] = sScore[j + 1];
sNames[j] = sNames[j + 1];
sScore[j + 1] = tempScore;
sNames[j + 1] = tempName;
isSort=true;
}
}
if(!isSort)break;
}
for(int i = stuNum - 1; i >= 0;i--){
System.out.println("第"+(stuNum - i)+"名"+sNames[i]+""+sScore[i]);
}
}
}

import java.util.Scanner;


public class StudentInAndOut {
private String name;
private long grade;

public long getGrade() {
return grade;
}
public void setGrade(long grade) {
this.grade = grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public String toString(){
return this.name;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生数");
int stuNumT = sc.nextInt();
StudentInAndOut objArr[] = new StudentInAndOut[stuNumT];
for(int i = 0; i < objArr.length; i++){
objArr[i] = new StudentInAndOut();
System.out.println("请输入第" + (i+1) + "个学生的姓名");
String name = sc.next();
objArr[i].setName(name);
System.out.println("请输入第" + (i+1) + "个学生的成绩");
long grade = sc.nextLong();
objArr[i].setGrade(grade);
}
System.out.println("打印开始:");
for(int i = 0; i < objArr.length; i++){
for(int j = i+1; j < objArr.length; j++){
if(objArr[i].getGrade() < objArr[j].getGrade()){
StudentInAndOut s = new StudentInAndOut();
s = objArr[i];
objArr[i] = objArr[j];
objArr[j] = s;
}
}
}
for(int i=0; i < objArr.length; i++){
System.out.println(objArr[i].getName()+"的成绩是:"+objArr[i].getGrade());
}
}
}

import java.util.Scanner;

class StudentInfo {
private String stuno;
private int score;

public String getStuno() {
return stuno;
}

public void setStuno(String stuno) {
this.stuno = stuno;
}

public int getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

}

public class Test205 {

public static void main(String[] args) {

StudentInfo[] stu = new StudentInfo[20];
Scanner scan = new Scanner(System.in);
int nCount = 0;
System.out.println("请输入输入的学生个数:");
nCount = scan.nextInt();
System.out.println("请输入输入的学生学号和分数(以空格隔开):");

int nCurrent = 0;
while (nCurrent < nCount) {
Scanner sca = new Scanner(System.in);
String strLine = sca.nextLine();

String[] strLineArr = strLine.split(" ");
StudentInfo st = new StudentInfo();
st.setStuno(strLineArr[0]);
st.setScore(Integer.parseInt(strLineArr[1]));
stu[nCurrent] = st;
nCurrent++;
}

// 排序
for (int i = 0; i < nCount; i++) {
for (int j = 0; j < nCount - i - 1; j++) {
if (stu[j].getScore() > stu[j + 1].getScore()) {
StudentInfo tmp = new StudentInfo();
tmp.setStuno(stu[j].getStuno());
tmp.setScore(stu[j].getScore());

stu[j].setStuno(stu[j + 1].getStuno());
stu[j].setScore(stu[j + 1].getScore());

stu[j + 1].setStuno(tmp.getStuno());
stu[j + 1].setScore(tmp.getScore());
}
}
}
// 输出学生信息
System.out.println("学号    分数");

for (int i = 0; i < nCount; i++) {
System.out.println(stu[i].getStuno() + "   " + stu[i].getScore());
}

}

}

运行结果如下:



建一个学生类啊,有学号和成绩两个属性

java编程:编写一个文件信息存储程序,用户通过键盘输入学生的姓名,性 ...
答:if(str.equals("y"))break; //如果输入的是y则退出程序 i++;} //关闭流 bw.close();fw.close();}catch(IOException ex1){ System.out.println ("输入输出异常");} System.out.println ("程序结束");} } 本人刚入手java 可能写得不是很好.. 希望能给你带来帮助..不足之处,敬请...

编写程序,提示用户输入一个数并显示该数,使用字符模拟七段显示器的...
答:include<stdio.h>#include<stdbool.h>#defineMAX_DIGHTS 10/* 0 1 _ 4 |_| 2 |_| 5 6 */boolsegments[10][7]= {{true,true,true,false,true,true,true}, /*0*/ {false,false,false,false,true,true,false},/*1*/ {true,false,true,true,true,fal...

利用C#编写一个控制台应用程序,实现用户输入学号,姓名,班级等信息后...
答:using System;using System.Collections.Generic;using System.Text;using System.Data.OleDb;using System.Data;using System.Text.RegularExpressions;namespace Demo6{ class Program { static void Main(string[] args) { Console.WriteLine("学号"); string xuehao = Console.ReadLine...

用java编写程序:提示用户输入一个点(x,y),
答:import java.util.Scanner;public class E3_22 { public static void main(String[] args) { Scanner input = new Scanner(System.in);System.out.print("输入十字坐标系中的一个点,例如 4 5 :");double x = input.nextDouble();double y = input.nextDouble();double distance = Math....

VF编写出一个学生查询程序,要求接受用户输入的学生姓名,如果找到就显 ...
答:accept "请输入学生:" to xh use student count to fhtj for 姓名=allt(xh)&&我本语句统计符合条件的记录个数!if fhtj=0 wait ("对不起,查无此人!按任意键退出...")else if fhtj=1 loca for 姓名=allt(xh)disp else loca for 姓名=allt(xh)n=1 do whil n<=fhtj ?"这是符合条件...

用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别...
答:/ 用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩 / //FileName: stuinfo.c include <stdio.h> include <stdlib.h> include <string.h> define SERIALLEN 20 define COURSENUM 3 typedef struct { char course[SERIALLEN];float score;}...

编写一个程序,根据某个班级学员的成绩,计算该班学员的平均成绩.班级的...
答:printf("请输入该班级的学员的总数:"); scanf("%d",&renshu); for (i = 1;i<=renshu;i++){ printf("请输入学号%d,的成绩:",i); scanf("%lf",&chengji); sum += chengji; fflush(stdin); } printf("\n");...

编写一个程序运行时首先由程序生成一个随机数M,然后提示用户输入一个数...
答:include <stdio.h>#include <stdlib.h>#include int main(){srand(time(0));int M = (rand() % 100) + 1;int n;while (scanf("%d", &n) != EOF){if (n == M){printf("恭喜你,猜中了\n");break;}else if (n < M)printf("猜小了\n");elseprintf("猜大了\n");}re...

用C++编写一个程序 a.提示用户输入5个小数 b.打印这5个小数 c.将每一...
答:for(i=0; i<5; i++)///输入5个小数 { scanf("%f", &f[i]);} sum = 0;for(i=0; i<5; i++){ t = f[i] - (int)f[i];///根据小数部分和0.5的比较,决定是向上取整,还是向下取整 if(t<0.5){ a[i] = (int)f[i];} else a[i] = (int)f[i] + 1;sum +...

编写一个程序,先提示用户输入数字0~25的数字,在用户输入数字后,程序能...
答:C语言源程序:include "stdio.h"void main(){ int num;char ch;do { printf("input a num : ");scanf("%d", &num);}while(num<0 || num>25);ch = num + 97;printf("%d : %c\n", num, ch);} 运行测试:input a num : 5 5 : f ...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网