zoukankan      html  css  js  c++  java
  • 每日代码系列(9)

     1 class Cylinder {
     2   private double radius;
     3   private int height;
     4   private double pi=3.14;
     5   private String color;
     6   public double setCylinder(double r,int h) {
     7     radius=r;
     8     height=h;
     9     return r+h;
    10   }
    11   public void setCylinder(String str) {
    12     color=str;
    13   }
    14   public void show() {
    15     System.out.println("颜色为:"+color);
    16   }
    17   double area() {
    18     return pi*radius*radius;
    19   }
    20   double volume() {
    21     return area()*height;
    22   }
    23 }
    24 public class C1_1 {
    25   public static void main(String[] args) {
    26     double r_h;
    27     Cylinder volu=new Cylinder();
    28     r_h=volu.setCylinder(2.5,5);
    29     volu.setCylinder("红色");
    30     System.out.println("半径和高之和="+r_h);
    31     System.out.println("体积="+volu.volume());
    32     volu.show();
    33   }
    34 }
  • 相关阅读:
    prayer OJ M
    51nod1295
    纪念第一次ak。。。
    noip2007-4
    51nod1344
    51nod1079
    51nod1537
    51nod1269Devu and Flowers
    python基本数据类型之列表list
    Python基本数据类型
  • 原文地址:https://www.cnblogs.com/ljydbk/p/14085353.html
Copyright © 2011-2022 走看看