用java编程,设计一个学生类,要求包含姓名年龄、性别、java成绩、c++成绩、php成绩

2024-11-18 20:30:10
推荐回答(2个)
回答(1):

public class Student{ private String name; private String sex; private int score_java; private int score_c; private int score_php; void averagescore() { int sum = 0; int average = 0; sum += score_java+score_c+score_php; average = sum/3; System.out.println("总分:" + sum); System.out.println("平均分:" + average); } void maxminscore() { int temp = 0; int max = 0; int min = 0; temp = score_java; if(tempscore_php) min = score_php; max = temp; System.out.println(" 最高分:" + max); System.out.println(" 最低分:" + min); }}

回答(2):

public class Student{ 
        private String name; 
        private String sex; 
        private int score_java; 
        private int score_c; 
        private int score_php; 
    void averagescore() { 
        int sum = 0; 
        int average = 0; 
        sum += score_java+score_c+score_php; 
        average = sum/3; 
        System.out.println("总分:" + sum); 
        System.out.println("平均分:" + average); 
    } 
    void maxminscore() { 
        int temp = 0; 
        int max = 0; 
        int min = 0; 
        temp = score_java; 
        if(temp        temp = score_c; 
        esle min = score_c; 
        if(temp        temp = score_php; 
        else if(min>score_php) 
        min = score_php; 
        max = temp; 
    System.out.println(" 最高分:" + max); 
    System.out.println(" 最低分:" + min); 
    }
}
稍微排了排版,看着能舒服点。