繁体   English   中英

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

[英]“Can't find symbol” error in the java.math.BigInteger class

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

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

我的代码如下,

    /* package whatever; // don't place package name! */

    import java.util.*;
    import java.lang.*;
    import java.io.*;

    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        int remainderWith7(String num)
        {
            // Your code here
            java.math.BigInteger bg=new java.math.BigInteger(num);
            Integer n=java.math.bg.intValue();
            //int n=java.util.Integer.parseInt(num);
            //hello
            return (int)n%7;
        }
        public static void main (String[] args) throws java.lang.Exception
        {
            // your code goes here
            Ideone id=new Ideone();
            id.remainderWith7("10");
        }
    }

请帮忙。 谢谢。

数学中没有名为bg属性。

将行更改为:

Integer n= bg.intValue();
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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM