JAVA 從鍵盤中輸入成績計算平均成績以及函數的調用


import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //創建一個學生對象
        Student s = new Student();
        //創建一個學生成績對象
        StudentScore sc = new StudentScore();
        //從控制台接收學生成績
        Scanner input = new Scanner(System.in);
        //提示用戶輸入學生成績
        System.out.println("please enter three score");
        //定義控制台輸入的參數
        s.Java = input.nextInt();
        s.SQL = input.nextInt();
        s.English = input.nextInt();
     //調用方法
        System.out.println("該同學的平均成績為:" + sc.calcAvg(s));
    }
}
public class Student {
    //定義一個學生類
    int Java;
    int SQL;
    int English;

}
 
public class StudentScore {
    //定義一個學生的平均成績 
    public double calcAvg(Student s1) {
        double avg = 0;
        avg = (s1.Java + s1.SQL + s1.English) / 3.0;
        return avg;

    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM