当所需要操作的数超过64位,即long型操作数的范围时,BigInteger(同BigDecimal)就体现了他的便利性,位于java.math包中,最常用的几个方法下图列出(图是盗来的),第一个构造方法,形参是String类型啊!小白我写的时候用的n.equals(0)根本没卵用,感觉自己傻得冒鼻涕泡,当然你知道的n是BigInteger类型。自从做了hdu1002就想写一篇关于大数的文,奈何当时只是初步接触学着用这两个类,现在做了几个题,感觉稍微好那么一点点了才敢写。
感觉小白我写的这些就像是日记啊!哎呀,不管了,可能就是把这个东西当做一个日记本来用的吧。。。。
HDU1013
import java.math.BigInteger;
import java.util.Scanner;
//b=(a-1)%9+1
public class hdu1013 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String n=sc.next();
if(n.equals("0"))
return;
else
{
BigInteger nine=new BigInteger("9");
BigInteger one=new BigInteger("1");
BigInteger b=new BigInteger(n);
b=b.subtract(one);
b=b.mod(nine);
b=b.add(one);
System.out.println(b);
}
}
}
}