我正在尝试为输入String的函数编写代码,并将它的余数作为“int”除以7时返回。 出于某种原因,我得到了下面的错误,java.math.BigInteger类中的“无法找到符号”错误
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'是你的变量只是名字。你为什么试图用'java.math'来限定它?只要使用'Integer n = bg.intValue();'(另外请注意,你提供的代码与你所显示的错误信息不符 - 总是值得确保你的一致性。) –
@JonSkeet谢谢您。这完全奏效。 – iamrkcheers