栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java——实验5

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java——实验5

程序设计1

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;



public class MyBookUtil {



    // 检查目标字符串中是否包含指定的关键字

    public static boolean check(String info, String key) 

    {

        // 在此完成方法的定义

        return info.contains(key); 

    }



    // 截取图书信息中的书名

    public static String getName(String info)

    {

        // 在此完成方法的定义

        return info.substring(info.indexOf("书名:")+3,info.indexOf(",出版时间"));

    }



    // 截取图书信息中的价格

    public static double getPrice(String info) 

    {

        // 在此完成方法的定义        

        return Double.parseDouble(info.substring(info.indexOf("价格:")+3,info.indexOf("元,页数")));

    }



    // 截取图书信息中的页码

    public static int getPage(String info) {

        // 在此完成方法的定义

        return Integer.parseInt(info.substring(info.indexOf("页数:")+3,info.lastIndexOf("页")));

    }

}

 程序设计2

import java.math.BigInteger;

public class BigCalc {
    private BigInteger num1;
    private BigInteger num2;

    public BigCalc(String str1, String str2) {
        num1 = new BigInteger(str1);
        num2 = new BigInteger(str2);
    }

    // 加法运算
    public BigInteger doAdd() 
    {
        return num1.add(num2);    
    }

    // 减法运算
    public BigInteger doSub() 
    {
        return num1.subtract(num2);
    }

    // 乘法运算
    public BigInteger doMult() 
    {
        return num1.multiply(num2);
    }

    // 除法运算
    public BigInteger doDiv() 
    {
        return num1.divide(num2);
    }

    // 获取因子个数
    public static BigInteger getFactorCount(BigInteger num) 
    {
        BigInteger count = new BigInteger("0"); // 计数结果
        BigInteger zero = BigInteger.ZERO; // BigInteger内置字段,代表0
        BigInteger one = BigInteger.ONE; // BigInteger内置字段,代表1
        // 在此完成方法的定义,获取参数num的因子的个数
        
        for(BigInteger temp = BigInteger.ONE;temp.compareTo(num)<0;temp=temp.add(one))
            if(num.remainder(temp)==zero)
                count=count.add(one);
        return count;
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/821029.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号