日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java实现一个学生类Student

發布時間:2023/12/16 java 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java实现一个学生类Student 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 1、設計一個類Student,該類包括姓名、學號和成績。設計一個方法,按照成績從高到低的順序輸出姓名、學號和成績信息。
public class Student {public static void main(String[] args) {Student [] num =new Student [3]; //創建一個一維數組num[0] = new Student ("scc",112,123); //為一維數組賦值num[1] = new Student ("sca",2018,1234);num[2] = new Student ("scb",2019,1235);// Student temp = new Student (); //兩種調用方法,使用這一種,需要在寫一個無參的構造方法。一般都用下面的方法。 // temp.swap(num);Student .swap(num); //類名.方法名for(Student stu : num){ //foreach循環,for(元素類型t 元素變量x : 遍歷對象obj)stu.show();}}private String name;private int number;private int score;// public String getName() { // return name; // } // public void setName(String name) { // this.name = name; // } // public int getId() { // return number; // } // public void setId(int id) { // this.number = number; // } // public int getScore() { // return score; // } // public void setScore(int score) { // this.score = score; // }public Student (){ }public Student (String name,int number,int score){//super();this.name = name;this.number = number;this.score = score;}public void show(){System.out.println("姓名:" + name + "學號: " + number + "成績" + score);}public static void swap(Student [] stus){//String temp; //這樣定義的錯誤,是因為,在下面交換的是stus[j],而stus是StudentTrue來定義的所以,如下定義Student temp; for(int i = 0;i < stus.length-1;i++){for(int j = 0;j < stus.length - i - 1;j++){if(stus[j].score > stus[j + 1].score){temp = stus[j]; //整個數組都變換,而不是僅僅變換成績stus[j + 1] = stus[j];stus[j] = temp;}}}} }

總結

以上是生活随笔為你收集整理的Java实现一个学生类Student的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。