英文:
I keep getting an error when i use Arrays.toString() method
问题
public class GFG {
public static void main(String[] args) {
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
结果:
/GFG.java:16: 错误: 找不到符号
System.out.println(Arrays.toString(boolArr));
^
符号: 变量 Arrays
位置: 类 GFG
1 错误
我尝试了多次,但一直得到这个错误。问题出在哪里?
英文:
public class GFG {
public static void main(String[] args)
{
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
Result:
/GFG.java:16: error: cannot find symbol
System.out.println(Arrays.toString(boolArr));
^
symbol: variable Arrays
location: class GFG
1 error
I tried a number of times and keep getting this error.
What's the issue here?
答案1
得分: 3
import java.util.*;
public class GFG {
public static void main(String[] args)
{
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
英文:
import java.util.*
in your code.
Like this
import java.util.*;
public class GFG {
public static void main(String[] args)
{
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
答案2
得分: 2
请注意,这不是一个专业的解释,但这将帮助您理解发生了什么。
您会收到此错误,是因为您没有在您的代码中导入Arrays
类。Arrays
不是一个关键字,而是一个类。由于它不是一个关键字,编译器不知道它的实现方式。因此,您必须导入该代码的实现。这意味着您必须告诉编译器,“嘿,这是Arrays
的意思。”然后编译器知道如何处理Arrays
。
在您的代码顶部添加以下行。
import java.util.Arrays;
现在编译器知道Arrays
的含义。
英文:
Please consider that, this is not a professional explanation. But this will help you to understand what is going on.
You get this error because you have no import the Arrays
class into your code. The Arrays
is not a keyword. It's a Class. Since it is not a keyword, the compiler doesn't know the implementation of that. So you have to import the implementation of that code. That means you have to tell the compiler, hey this is the meaning of Arrays
. Then the compiler knows what to do with Arrays
.
Add the following line to the top of your code.
import java.util.Arrays;
Now the compiler knows the meaning of the Arrays
.
答案3
得分: 1
你需要导入 import java.util.Arrays
import java.util.Arrays
public class GFG {
public static void main(String[] args)
{
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
英文:
You need to import import java.util.Arrays
import java.util.Arrays
public class GFG {
public static void main(String[] args)
{
int[] intArr = new int[] { 1, 2, 3, 4 };
System.out.println(Arrays.toString(intArr));
}
}
答案4
得分: 0
在你的代码的第一行,在类之前,导入这个包和类 **Arrays**:
**import java.util.Arrays;**
英文:
import this package with class Arrays as the first line of your code before class
import java.util.Arrays;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论