当前位置:首页 » 考试成绩 » java输入输出学生成绩

java输入输出学生成绩

发布时间: 2021-01-03 10:05:21

1. java中 使用switch语句实现学生成绩等级

#include <stdio.h>

int main()

{

double score;

int nKey;

while (scanf_s("%lf", &score) == 1)

{

if (score < 0 || score > 100)

{

printf("请输入0-100范围内的分数 ");

continue;

}

nKey = (int)score / 10;

switch (nKey)

{

case 0:

case 1:

case 2:

case 3:

case 4:

case 5:

printf("E ");

break;

case 6:

printf("D ");

break;

case 7:

printf("C ");

break;

case 8:

printf("B ");

break;

case 9:

case 10:

printf("A ");

break;

default:

break;

}

}

return 0;

}

(1)java输入输出学生成绩扩展阅读:

switch用法

一般形式:

switch(表达式){

case 常量表达式1: 语句1;

case 常量表达式2: 语句2;

case 常量表达式n: 语句n;

default: 语句n+1;

}

意思是先计算表达式的值,再逐个和case 后的常量表达式比较,若不等则继续往下比较,若一直不等,则执行default后的语句;若等于某一个常量表达式,则从这个表达式后的语句开始执行,并执行后面所有case后的语句。

与if语句的不同:If语句中若判断为真则只执行这个判断后的语句,执行完就跳出if语句,不会执行其他if语句;而switch语句不会在执行判断为真后的语句之后跳出循环,而是继续执行后面所有case语句。

在每一case语句之后增加break 语句,使每一次执行之后均可跳出switch语句,从而避免输出不应有的结果。

参考资料来源:switch-网络

2. java中 使用switch语句实现学生成绩等级

//通过控制台输入分数
public
static
void
main(String[]
args){
System.out.println("请输入分数:");
Scanner
input=new
Scanner(system.in);
int
i=input.nextInt();
i=i/10;
switch(i){
case
10:
case
9:
System.out.println("A");
break;
case
8:
System.out.println("B");
break;
case
7:
System.out.println("C");
break;
case
6:
System.out.println("D");
break;
default:
if(i>=0&&
i<=10){
System.out.println("E");
}else{
System.out.println("输入的数不是有效分数");
}
break;
}
}
或者
switch
(i)
{
case
100:
case
90:
System.out.println("分数是"
+
i
+
"
等级为A");
break;
case
80:
System.out.println("分数是"
+
i
+
"
等级为B");
break;
case
70:
System.out.println("分数是"
+
i
+
"
等级为C");
case
60:System.out.println("分数是"
+
i
+
"
等级为D");
default:
if(i>=0&&
i<=10){
System.out.println("分数是"
+
i
+
"
等级为E");
}else{
System.out.println("输入的数不是有效分数");
}break;
}

3. Java输入输出流 文件类 学生成绩

第一个抄
文件输出流袭
BufferedWriter bw = new BufferWriter(new FileInputStream(new File("studnet.txt")));

for(...)
bw.write(Studnet.toString());//写入学生信息
bw.flush();
bw.close;
第二个
文件输入流
BufferedReader br = new BufferedReader(new FileOutputStream(new File("studnet.txt")));
String temp = null;
while((temp = br.readLine()!=null)){//读取文件类容
syso(temp);
}

4. Java编程,定义一个学生类,输入3个学生数据,输出平均分和总分

public class Student { public static void main(String[] args) { StudentInfo zhangsan = new StudentInfo("张三", 1, 99); StudentInfo lisi = new StudentInfo("李四", 2, 203); StudentInfo wangwu = new StudentInfo("王五", 3, 357); StudentInfo xiaohong = new StudentInfo("小红", 4, 642); StudentInfo xiaozhang = new StudentInfo("小张", 5, 346); } } class StudentInfo{ public String name; public int num; public int score; public StudentInfo(String name,int num,int score){ this.name = name; this.num = num; this.score = score; }}

5. 怎样用java编写程序实现学生成绩等级划分,输入考试成绩,程序会相应输出成绩等级

import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.println("请输入成绩");
int a=x.nextInt();
int n=a/10; //百分制转换为等第
switch(n){
case 10: //表示如果n=10,也就是一百分,输出A
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
System.out.println("FAIL"); //低于六十分的输出不及格 FAIL
break;
default:System.out.println(" 请输入一个正确的成绩"); //输入的不是百分制,报错
}
}
}

6. 用Java编程输入学生成绩的等级,给出相应的成绩范围。

class SwitchTest
{
public static void main(String[] args)
{
char a='\0';
System.out.println("Please input a charactar");
try
{
a=(char)System.in.read();
}catch(Exception e)
{
System.out.println(e);
}
switch(a)
{
case 'A':System.out.println("范围在85~");break;
case 'B':System.out.println("范围在70~85");break;
case 'C':System.out.println("范围在60~70");break;
case 'D':System.out.println("范围在60分以下");break;
}
}
}

class ifTest
{
public static void main(String[] args)
{
char a='\0';
System.out.println("Please input a charactar");
try
{
a=(char)System.in.read();
}catch(Exception e)
{
System.out.println(e);
}
if(a=='A')
System.out.println("范围在85~100");
if (a=='B')
System.out.println("范围在70~85");
if(a=='C')
System.out.println("范围在60~70");
if(a=='D')
System.out.println("范围在60分以下");
}
}

我这样的修改是不是符合你的意思啊!

7. 急!急1急!用java编写简单的学生成绩录入程序

User
u
=
new
User();
List<User>
list
=
new
ArrayList<User>();
Scanner
in
=
new
Scanner(System.in);
System.out.println("请输入学生总数:");
int
t
=
in.nextInt();
int
math
=
0;
int
pc
=
0;
int
sql
=
0;
for(int
i=1;i<=t;i++){
u.setId(i);
System.out.println("请输入第"
+
i
+
"个人的数学成绩");
math
=
in.nextInt();
u.setMath(math);
System.out.println("请输入第"
+
i
+
"个人的计算专机成绩");
pc
=
in.nextInt();
u.setPc(pc);
System.out.println("请输入第"
+
i
+
"个人的数据库属成绩");
sql
=
in.nextInt();
u.setSql(sql);
list.add(u);
}

8. 编一程序从键盘输入5学生的JAVA课程成绩,然后 输出这5个学生的成绩

搜一下:编一程序从键盘输入5学生的JAVA课程成绩,然后
输出这5个学生的成绩

9. 如何用Java实现“学生成绩输入”问题

import java.util.Scanner;
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;
}
}
//代码没有交换学生数组下标,麻烦提问者再修改一下吧,真的要睡了,明天继续上班,抱歉,只能帮你到这里了。

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919