當前位置:首頁 » 考試成績 » 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