zoukankan      html  css  js  c++  java
  • java输出各种学生成绩

     1 class stu
     2 {
     3     public String stuno;
     4     public String name;
     5     public float math;
     6     public float english;
     7     public float computer;
     8     public float sum;
     9     public float average;
    10     stu(String stuno1,String name1,float math1,float english1,float computer1) //构造函数
    11     {
    12         this.stuno = stuno1;
    13         this.name = name1;
    14         this.math = math1;
    15         this.english = english1;
    16         this.computer = computer1;
    17     }
    18     public void sum() //求和方法
    19     {
    20         sum = math + english + computer;
    21         System.out.println("sum = " + sum);
    22     }
    23     public void average() //求平均值方法
    24     {
    25         average = sum / 3;
    26         System.out.println("average = " + average);
    27     }
    28     public void max() //求最大值方法
    29     {
    30         float max;
    31         if(math > english)
    32             if(math > computer)
    33                 max = math;
    34             else
    35                 max = computer;
    36         else
    37             if(english > computer)
    38                 max = english;
    39             else
    40                 max = computer;
    41         System.out.println("最高分为:" + max);
    42     }
    43     public void min() //求最小值方法
    44     {
    45         float min;
    46         if(math < english)
    47             if(math < computer)
    48                 min = math;
    49             else
    50                 min = computer;
    51         else
    52             if(english < computer)
    53                 min = english;
    54             else
    55                 min = computer;
    56         System.out.println("最低分为:" + min);
    57     }
    58     public void print() //输出方法
    59     {
    60         System.out.println("姓名:" + name + " 学号:" + stuno );
    61         System.out.println("数学成绩:" + math + " 英语成绩:" + english + " 计算机成绩:" + computer);
    62     }
    63 }
    64 class Student
    65 {
    66     public static void main(String args[])
    67     {
    68         stu stu1 = new stu("2017025425","马云",99,88,77);
    69         stu1.print();
    70         stu1.sum();
    71         stu1.average();
    72         stu1.max();
    73         stu1.min();
    74     }
    75 }

    运行结果:

  • 相关阅读:
    下雪诗
    华视身份证阅读器100UC HTTP模式二次开发
    C# Action 和 Func 区别
    网站部署——文件系统
    前端-JavaScript DOM和BOM
    IO多路复用
    python-协程
    python-线程
    python-进程
    计算机与操作系统简介
  • 原文地址:https://www.cnblogs.com/YUJIE666/p/6764206.html
Copyright © 2011-2022 走看看