牟文琳


私信TA

用户名:dotcpp0716155

访问量:685

签 名:

等  级
排  名 687
经  验 3845
参赛次数 0
文章发表 60
年  龄 0
在职情况 学生
学  校 淄博职业学院
专  业

  自我简介:

解题思路: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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区