zoukankan      html  css  js  c++  java
  • 类名大写

         第一、类名要大写(Test);

         第二、可以有多个类,但是只能一个是public。

    import java.util.*;
    
    public class Test 
    {
    	public static void main(String[] args)
    	{
           Scanner sc = new Scanner(System.in);
           double oblength,obheight;
           Oblong myoblong;
           
           System.out.print("please enter the length");
           oblength = sc.nextDouble();
           System.out.print("please enter the height");
           obheight = sc.nextDouble();
           
           myoblong = new Oblong(oblength,obheight);
           System.out.println("length="+myoblong.getLength());
           System.out.println("height="+myoblong.getHeight());
           System.out.println("area="+myoblong.calculateArea());
           System.out.println("perimeter="+myoblong.calculatePerimeter());
    	}
    	
    }
    
    
    class Oblong
    {
      private double length;
      private double height;
      
      public Oblong(double a,double b)
      {
    	  length = a;
    	  height = b;
      }
      
      public double getLength()
      {
    	  return length;
      }
      public double getHeight()
      {
    	  return height;
      }
      public double calculateArea()
      {
    	  return length * height;
      }
      public double calculatePerimeter()
      {
    	  return 2*(length + height);
      }
    }
    
  • 相关阅读:
    PHP 单例 工厂模式 类的重载 抽象 接口
    上传文件
    ThinkPHP3.2中if标签
    JS闭包特性 运算符 DOM操作
    循环数组 连接数据库 AJAX
    ThinkPHP
    TP框架
    MVC框架
    类的自动加载,静态属性静态方法
    魔术方法__get()和set函数
  • 原文地址:https://www.cnblogs.com/HpuAcmer/p/2378454.html
Copyright © 2011-2022 走看看