• 包装类习题和知识


    包装类作用主要是包装基本数据类型,包装为对象数据类型

    例:实现大小写字母的相互转换

    package *;
    class A{
    	private char ch;

    public A(){} public A(char ch){this.ch=ch;}
    public char getCh(){return this.ch;} public char daXie(){ if (ch>='A' && ch<='Z') {   return (char)(ch+32);//ASCII是Unicode的子集 } return ch; } public char xiaoXie(){ if (ch>='a' && ch<='z') { return (char)(ch-32); } return ch; } } public class San { public static void main(String[] args) { char ch='r'; A a=new A(ch); char c=a.getCh(); System.out.println(c); } }

      定义一个抽象类,实现圆形,矩形和三角形的面积计算。

    package *;
    abstract class TuXing{
    	public abstract double getMianJi();
    }
    class Yuan extends TuXing{
    	private double r;
    	public Yuan(){};
    	public Yuan(double r){this.r=r;}
    	public double getMianJi() {
    		return Math.PI*r*r;
    	}
    }
    class JuXing extends TuXing{
    	private double x;
    	private double y;
    	public JuXing(){}
    	public JuXing(double x, double y){
    	  this.x=x;this.y=y;
    	}
    	public double getMianJi() {
    		return x*y;
    	}
    }
    class Sanjiaoxing extends TuXing{
    	private double a;
    	private double b;
    	private double c;
    	public Sanjiaoxing(){}
    	public Sanjiaoxing(double a,double b,double c){
    		this.a=a;this.b=b;this.c=c;
    	}
    	public double getMianJi() {
    		double p=(this.a+this.b+this.c)*0.5;
    		double d=p*(p-this.a)*(p-this.b)*(p-this.c);
    		double mianji=Math.sqrt(d);
    		return mianji;
    	}
    }
    public class Wu {
    	public static void main(String[] args) {
    		System.out.println(method(new Yuan(2)));
    		System.out.println(method(new JuXing(2,3)));
    		System.out.println(method(new Sanjiaoxing(3,4,5)));
    	}
    	public static double method(TuXing tuXing) {
    		return tuXing.getMianJi();
    	}
    }
    

      

  • 相关阅读:
    conda 激活环境失败解决办法
    openSmile-2.3.0在Linux下安装
    Ubuntu16.04下安装多版本cuda和cudnn
    几个最新免费开源的中文语音数据集
    train loss与test loss结果分析
    文件路径
    Properties类与配置文件
    内省
    Junit单元测试
    Hdfs常用命令
  • 原文地址:https://www.cnblogs.com/dldrjyy13102/p/7599128.html
Copyright © 2020-2023  润新知