[转]POJ 1001 Exponentiation Java大数处理高精度小数
来源:互联网 发布:nginx body filter 编辑:程序博客网 时间:2024/04/30 14:13
之前写过用C++来实现,不过用C++实在太麻烦了,最近才发现用Java来处理大数问题非常方便,不过Java刚学还并不太会,所以转载一篇先记录一下~
转自http://blog.sina.com.cn/s/blog_694034130100wpxj.html
import java.math.BigDecimal;import java.util.Scanner;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); while (in.hasNext()) { BigDecimal R = in.nextBigDecimal(); int n = in.nextInt(); R = R.pow(n); String str = R.stripTrailingZeros().toPlainString(); if (str.startsWith("0.")) str = str.substring(1); System.out.println(str); } }}
说明:
1、stripTrailingZeros() ,返回类型为BigDecimal的小于此数的但除去尾部的0的数值。
2、toPlainString(),返回BigDecimal类型的String类型字符串。
3、startsWith(),确定此实例的开头是否与指定的字符串匹配。
4、substring(),返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾。
1 0
- [转]POJ 1001 Exponentiation Java大数处理高精度小数
- POJ 1001 Exponentiation 高精度小数相乘
- POJ 1001 Exponentiation (高精度/大数乘法)
- POJ 1001 Exponentiation (Java高精度)
- poj 1001 Exponentiation JAVA大数
- Exponentiation 【java 处理高精度】
- poj 1001 uva 748 Exponentiation(高精度小数乘法)
- POJ 1001 Exponentiation(大数处理)
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- POJ-1001 Exponentiation 高精度
- Exponentiation - POJ 1001 高精度
- POJ 1001 Exponentiation【高精度用java】
- POJ 1001 Exponentiation(大数)
- 【POJ】 1001 Exponentiation 大数
- POJ 1001 Exponentiation(大数幂Java实现)
- Exponentiation(POJ-1001) Java大数例题
- hdu1063 Exponentiation 高精度小数
- poj 1001 (Exponentiation) 高精度乘法
- Linux学习_第一章计算机结构001
- c中三个数的排序
- 蓝桥杯 历届试题 九宫重排 (八数码问题--康托展开去重 + bfs搜索)
- nyoj 973 天下第一
- Vue入门知识点—初识vue
- [转]POJ 1001 Exponentiation Java大数处理高精度小数
- NGUI学习笔记(六):ScrollView、Grid和Table
- 【转载】在erlang项目中使用protobuf
- CodeForces 627 B.Factory Repairs(BIT)
- 如何用递归算法判断一个数组是否递增
- bzoj 4031: [HEOI2015]小Z的房间 矩阵树定理
- android获取周围基站信息
- 对象反序列化时,如果父类未实现序列化接口,则反序列出的对象会再次调用父类的构造函数来完成属于父类那部分内容的初始化
- 第六天-网页的head制作——明天继续写下面的