• 设计并实现大数类 BigNum


    学习任务:设计并实现大数类 BigNum

    代码示例:

    import java.util.Scanner;

    public class BigNum {

    private double num;
    public BigNum(double c) {
    num=c;
    System.out.println("BigNum Constructorrun");
    }
    public void setNum(double c) {
    num=c;
    }
    public final double getNum() {
    return num;
    }
    public final void show() {
    System.out.println("BigNum("+num+")");
    }

    public static void main(String[] args) {
    double c1,c2;
    String op;
    System.out.println("请输入c1:");
    Scanner sc=new Scanner(System.in);
    c1=sc.nextDouble();
    BigNum b1=new BigNum(c1);
    BigNum b2=b1;
    b1.show();
    System.out.println("请输入c2:");
    Scanner sc1=new Scanner(System.in);
    c2=sc1.nextDouble();
    b2.setNum(c2);
    b2.show();
    System.out.println("请输入op:");
    Scanner sc2=new Scanner(System.in);
    op=sc2.next();
    if(op.equals("+")) {
    BigNum b3=new BigNum(c1+c2);
    b3.show();
    }
    if(op.equals("-")) {
    BigNum b4=new BigNum(c1-c2);
    b4.show();
    }

    }

    }

    运行截图:

     明天任务:以点类 Point 及平面图形类 Plane 为基础设计三角形类 Triangle

  • 相关阅读:
    微信小程序支付
    python中 try、except、finally执行顺序
    磁盘设备在 Linux 下的表示方法
    sanic中间件和监听器
    sed命令详解
    awk命令详解
    gd库
    php中计算二维数组中某一元素之和
    Linux SVN 命令详解
    PHP array 操作函数
  • 原文地址:https://www.cnblogs.com/zyj3955/p/13424467.html
Copyright © 2020-2023  润新知