• 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 }

    运行结果:

  • 相关阅读:
    POJ 1654 Area 多边形面积 G++会WA
    POJ 3348 Cows 求凸包面积
    POJ 1279 Art Gallery 半平面交 多边形的核
    hdu 1556 Color the ball 线段树 区间更新
    POJ 1474 Video Surveillance 半平面交
    POJ 3130 How I Mathematician Wonder What You Are! 半平面交
    在React项目中,如何优雅的优化长列表
    react高亮显示关键词
    通过a标签同源和跨域下载服务器文件(基于blob)
    前端性能优化之回流和重绘
  • 原文地址:https://www.cnblogs.com/YUJIE666/p/6764206.html
Copyright © 2020-2023  润新知