import java.util.Scanner;
丁青網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
public class Student{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("請輸入學(xué)生的人數(shù)....");
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)+"個(gè)學(xué)生的序號!");
st.setId(sc.nextInt());
System.out.println("請輸入第"+(arr[i]+1)+"個(gè)學(xué)生的姓名!");
st.setName(sc.next());
System.out.println("請輸入第"+(arr[i]+1)+"個(gè)學(xué)生的成績!");
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;// 記下較大數(shù)位置,再次比較,直到最大
}
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("成績?yōu)椋?+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;
}
}
//代碼沒有交換學(xué)生數(shù)組下標(biāo),麻煩提問者再修改一下吧,真的要睡了,明天繼續(xù)上班,抱歉,只能幫你到這里了。
這里有一個(gè)類
實(shí)現(xiàn)學(xué)生學(xué)號,數(shù)學(xué),語文,英語成績錄入
并且計(jì)算平均成績,按照平均成績高低輸出信息
你可以改改!
//實(shí)現(xiàn)簡單的學(xué)生信息輸入輸出和初步的成績排序
public
class
student
{
private
int
id;
//學(xué)號
private
int
mathscore;
//數(shù)學(xué)成績
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)
{
//輸出對象的內(nèi)容
system.out.println("
"
+
student.id
+
"
"
+
student.mathscore
+
"
"
+
student.chinscore
+
"
"
+
student.forescore
+
"
"
+
student.getaveragescore());
}
public
int
max(student
a[],
int
n)
{
//student類對象數(shù)組的前n項(xiàng)中的成績最大值的索引
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類對象數(shù)組的選擇排序
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 demo16 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//循環(huán)錄入某學(xué)生5門課的成績并計(jì)算平均分。如果某分?jǐn)?shù)錄入為負(fù),停止錄入并提示錄入錯(cuò)誤 //循環(huán)錄入成績,判斷錄入正確性。錄入錯(cuò)誤,使用break語句立刻跳出循環(huán);否則,累加求和
double sum=0,score;
Scanner sc = new Scanner(System.in);
System.out.println("請輸入學(xué)生姓名:");
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("抱歉,分?jǐn)?shù)錄入錯(cuò)誤,請重新進(jìn)行錄入");
break;
}
}
System.out.println("平均分為:" + sum / 5);
}
}
本文名稱:java成績錄入代碼 用java編寫成績
轉(zhuǎn)載來源:http://www.rwnh.cn/article0/hicgio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、手機(jī)網(wǎng)站建設(shè)、微信公眾號、網(wǎng)站排名、軟件開發(fā)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)