题解 | #循环数比较#

循环数比较

http://www.nowcoder.com/practice/24575008c6134b6fa4fab8ea0ea82a99

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x1 = in.nextInt();
        int k1 = in.nextInt();
        int x2 = in.nextInt();
        int k2 = in.nextInt();
        BigInteger v1 = repeat(x1,k1);
        BigInteger v2 = repeat(x2,k2);
        int num = v1.compareTo(v2);
        if (num < 0)
            System.out.println("Less");
        else if (num > 0)
            System.out.println("Greater");
        else
            System.out.println("Equal");

    }
    public static BigInteger repeat(int x, int k){
        String str = Integer.toString(x);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < k; i++) {
            sb.append(str);
        }
        BigInteger num = new BigInteger(sb.toString());
        return num;
    }
}
全部评论

相关推荐

代码飞升:简历差不多情况下你的学历已经加分了,海投就行,加油,不要追求尽善尽美
点赞 评论 收藏
分享
路过的咸蛋超人也想拿offer:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务