我正在嘗試爲輸入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