大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这里有一个类
专注于为中小企业提供成都网站建设、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业汉源免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩排序
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;
}
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生的分数:");
double score = input.nextDouble();
int level1,level2;
if(score=60.0 score=100.0){
System.out.print("该学生成绩为优秀!");
}
else if(score=0 score60.0){
System.out.print("该学生成绩为不及格!");
}
else{
System.out.print("您输入的成绩有误!");
}
}
}
public static void main(String[] args) {
double scores[] = new double[5];
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=0;
String inputStr=null;
System.out.println("请输入5名学生的成绩:");
Scanner input = new Scanner(System.in);
while(count5){
try{
if(count 5){
System.out.println("请输入第"+(count+1)+"个分数:");
}
inputStr=input.nextLine();
scores[count++]=Double.valueOf(inputStr.trim());
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim())){
System.out.println("您已成功结束程序");
System.exit(0);
}
System.out.println("若想结束请输入:exit");
System.out.print("您输入的分数不是数值类型,");
count--;
}
}
input.close();
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("总成绩是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
//-------------------------------------------------------------------------
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(true){
Double[] scores = null;
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=1;
ListDouble inputScores=new ArrayListDouble();
String inputStr=null;
System.out.println("请输入要统计学生的成绩(理论上可以输入无限个,前提是你有那么大的内存):");
while(true){
try{
System.out.println("请输入第"+count+++"个分数,或输入ok进行计算,离开请输入exit");
inputStr=input.nextLine();
inputScores.add((double)Double.valueOf(inputStr.trim()));
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim().toLowerCase())){
System.out.println("您已成功结束程序");
input.close();
System.exit(0);
}
if(inputStr!=null "ok".equals(inputStr.trim().toLowerCase())){
break;
}
System.out.println("您输入的分数不是数值类型,");
System.out.println("若想结束请输入exit ,若想计算结果请输入ok");
count--;
}
}
if(inputScores.size()==0){
System.out.println("您没有输入学生成绩,无数据可统计,程序结束。");
return ;
}
scores=inputScores.toArray(new Double[inputScores.size()]);
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("总成绩是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("输入你的成绩");
int grade = s.nextInt();
if(grade = 60grade=70){
System.out.println("及格!!!!");
}else if(grade 70grade=85){
System.out.println("良好!!!!");
}else if(grade 85grade=100){
System.out.println("优秀!!!!");
}else{
System.out.println("不及格!!!!");
}
}