解题思路:Int放不下这个数字所以用BIgInteger
注意事项:
参考代码:
package test;
//求a的b次方的后三位
import java.util.Scanner;
import java.math.BigInteger;
public class miLastTree {
public static void main(String args[]) {
int a,b;
Scanner sc=new Scanner(System.in);
a=sc.nextInt();//初始赋值
b=sc.nextInt();
if(Math.pow(a,b)<100)//如果小于三位数只需要使用整形计算
{
if((int)Math.pow(a,b)/10!=0)//判断是两位数还是三位数,判断补几个0
System.out.printf("%d%d",0,(int)Math.pow(a,b));
else
System.out.printf("%d%d%d",0,0,(int)Math.pow(a,b));
}
else//如果大于三位数
{ String str=Integer.toString(a);//因为BigInteger中为字符串所以把底数转换为字符串
BigInteger temp=new BigInteger("1000");//用来求后三位数字的%数
BigInteger x=new BigInteger(str);
BigInteger y=x.pow(b);//求出来数值
System.out.print(y.remainder(temp));//直接输出%1000后的数字
}
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C++代码)浏览:853 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:667 |
简单的a+b (C语言代码)浏览:524 |
C语言考试练习题_排列 (C语言代码)浏览:720 |
C语言程序设计教程(第三版)课后习题8.2 (C语言代码)浏览:5231 |
简单的for循环浏览:1410 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:658 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:543 |
字符逆序 (C语言代码)浏览:619 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:605 |