java成绩录入代码 用java编写成绩
如何用Java实现“学生成绩输入”问题?
import java.util.Scanner;
丁青网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联公司自2013年创立以来到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司。
public class Student{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生的人数....");
int num = sc.nextInt();
int[] arr = new int[num];
double[] chengji_arr = new double[num]; //存放成绩的
String[] String_arr = new String[num]; //存放姓名的
String chengjis = "";
String names = "";
for(int i = 0; i arr.length i String_arr.length i chengji_arr.length; i++){
arr[i] = i;
int s = 0;
Students st = new Students();
System.out.println("请输入第"+(arr[i]+1)+"个学生的序号!");
st.setId(sc.nextInt());
System.out.println("请输入第"+(arr[i]+1)+"个学生的姓名!");
st.setName(sc.next());
System.out.println("请输入第"+(arr[i]+1)+"个学生的成绩!");
st.setChengji(sc.nextDouble());
String_arr[i] = st.getName(); //保存成绩
chengji_arr[i] = st.getChengji();
}
int max = 0;
int tmp = 0;
for (int i = 0; i chengji_arr.length; i++) {
max = i;
for (int j = i + 1; j chengji_arr.length; j++) {
if (chengji_arr[max] chengji_arr[j])
max = j;// 记下较大数位置,再次比较,直到最大
}
if (i != max) {
tmp = (int)chengji_arr[i];
chengji_arr[i] = chengji_arr[max];
chengji_arr[max] = tmp;
}
}
for (int i = 0; i chengji_arr.length; i++)
System.out.print("成绩为:"+chengji_arr[i] + " ");
}
}
class Students{
private int id;
private String name;
private double chengji;
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setChengji(double chengji){
this.chengji = chengji;
}
public double getChengji(){
return chengji;
}
}
//代码没有交换学生数组下标,麻烦提问者再修改一下吧,真的要睡了,明天继续上班,抱歉,只能帮你到这里了。
急!急1急!用java编写简单的学生成绩录入程序
这里有一个类
实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩排序
public
class
student
{
private
int
id;
//学号
private
int
mathscore;
//数学成绩
private
int
chinscore;
//语文成绩
private
int
forescore;
//外语成绩
public
student()
{
id
=
0;
mathscore
=
0;
chinscore
=
0;
forescore
=
0;
}
public
student(int
newid,
int
newmathscore,
int
newchinsvore,
int
newforescore)
{
id
=
newid;
mathscore
=
newmathscore;
chinscore
=
newchinsvore;
forescore
=
newforescore;
}
public
double
getaveragescore()
{
//求平均成绩
double
averagescore
=
((double)
mathscore
+
chinscore
+
forescore)
/
3;
return
averagescore;
}
public
void
output(student
student)
{
//输出对象的内容
system.out.println("
"
+
student.id
+
"
"
+
student.mathscore
+
"
"
+
student.chinscore
+
"
"
+
student.forescore
+
"
"
+
student.getaveragescore());
}
public
int
max(student
a[],
int
n)
{
//student类对象数组的前n项中的成绩最大值的索引
int
position
=
0;
for
(int
i
=
1;
i
n;
i++)
{
if
(a[i].getaveragescore()
a[position].getaveragescore())
{
//比较平均成绩
position
=
i;
}
}
return
position;
}
public
void
selectsort(student
a[])
{
//student类对象数组的选择排序
for
(int
n
=
a.length;
n
1;
n--)
{
int
i
=
max(a,
n);
student
temp
=
a[i];
a[i]
=
a[n
-
1];
a[n
-
1]
=
temp;
}
}
}
java用for循环录入某学生五门课程的成绩并计算平均分,如果分数为负,停止录入并提示错误。
import java.util.Scanner;
public class demo16 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//循环录入某学生5门课的成绩并计算平均分。如果某分数录入为负,停止录入并提示录入错误 //循环录入成绩,判断录入正确性。录入错误,使用break语句立刻跳出循环;否则,累加求和
double sum=0,score;
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生姓名:");
String name = sc.next();
for (int i = 1; i = 5; i++) {
System.out.println("请输入第" + i + "门课的成绩");
score=sc.nextDouble();
sum += score;
// double score = sc.nextDouble();
if (score 0) {
System.out.println("抱歉,分数录入错误,请重新进行录入");
break;
}
}
System.out.println("平均分为:" + sum / 5);
}
}
文章标题:java成绩录入代码 用java编写成绩
文章地址:http://ybzwz.com/article/hicgio.html