简体   繁体   中英

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

I'm trying to write code for a function that inputs String and returns its remainder when divided by 7 as an 'int'. For some reason I'm getting the following error,

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

My code is as follows,

    /* 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");
        }
    }

Please help. Thank You.

There is no attributes in math that's named bg .

Change the line to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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