java.math.BigInteger类中的“找不到符号”错误

时间:2016-11-26 13:22:48

标签: java

我正在尝试为输入String的函数编写代码,并在将7除以“int”时返回其余数。 出于某种原因,我收到以下错误,

for(i = 0; i < arr[i]; i++)
    printf("%d ", arr[i]);

我的代码如下,

    Main.java:16: error: cannot find symbol
        n=java.math.BigInteger.bg.intValue();
                          ^
    symbol:   variable bg
    location: class BigInteger
    1 error

请帮忙。 谢谢。

2 个答案:

答案 0 :(得分:2)

数学中没有名为bg的属性。

将行更改为:

Integer n= bg.intValue();

答案 1 :(得分:1)

import java.math.BigInteger;
import java.util.Scanner;

public class BigIntergerSumExample {

    public static void main(String args[]) {

        BigInteger number1;
        BigInteger number2;
        BigInteger sum;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value of number 1");
        number1 = sc.nextBigInteger();
        System.out.println("Enter the value of number 2");
        number2 = sc.nextBigInteger();


        BigInteger a = new BigInteger(""+number1);
        BigInteger b = new BigInteger(""+number2);
        BigInteger result = a.add(b);

        System.out.println("Sum is Two numbers : -> " + result);
    }

}


Answer is

Enter the value of number 1
1111111111111111111111111111111111111111111111111
Enter the value of number 2
2222222222222222222222222222222222222222222222222
Sum is Two numbers : -> 
3333333333333333333333333333333333333333333333333
相关问题