import java.util.scanner 没用过
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5223486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import java.util.scanner never used
提问by Mike
I get this error:
我收到此错误:
import java.util.scanner never used
import java.util.scanner 没用过
I'm not sure what I need to insert.
我不确定我需要插入什么。
import java.util.Scanner;
public class Diamond {
public static void diamondOfAsterisks() {
for (int i = 1; i < 10; i += 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
for (int i = 7; i > 0; i -= 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
}
}
回答by Brent Worden
Delete the import line as it is not needed. Nowhere in the code are you using that type.
删除导入行,因为它不需要。代码中没有任何地方使用该类型。
回答by Tropid
That's just a warning, because you never use java.util.Scanner
.
这只是一个警告,因为您从不使用java.util.Scanner
.
Just remove import java.util.Scanner;
and it should stop to complain.
只需删除import java.util.Scanner;
,它应该停止抱怨。
回答by Umesh K
Just remove the following import statement from your program.
只需从您的程序中删除以下导入语句。
import java.util.Scanner
回答by OscarRyz
That's not an error. Most likely a warning in your IDE that suggest you to remove this unused import.
那不是错误。很可能是 IDE 中的警告,建议您删除此未使用的导入。
In java you may have as many unused imports as you want, it doesn't impact the performance at all. But it is recommended to have only those you need, so your program is maintainable.
在 Java 中,您可以根据需要拥有任意数量的未使用导入,它根本不会影响性能。但建议只拥有你需要的那些,所以你的程序是可维护的。
So, to fix this, just delete that line.
因此,要解决此问题,只需删除该行即可。
回答by corsiKa
All the other answers are saying "Delete the Scanner import statment".
所有其他答案都在说“删除扫描仪导入语句”。
My question is... why was it in there in the first place?
我的问题是......为什么它首先在那里?
The purposeof the warning is to say "You have this import, but you're not using it. Did you mean to use this, and just forgot to add it?"
警告的目的是说“你有这个导入,但你没有使用它。你是想使用它,只是忘了添加它?”
I see those warnings as a quasi-to-do-list for my class. Most of the time it happens when I add something, remove it because it needs to be refactored, and haven't put it back in yet. So my guess is you had a Scanner in there, it wasn't working right, you took Scanner out, but the import was left.
我将这些警告视为我班级的准任务清单。大多数情况下,当我添加一些东西时会发生这种情况,因为它需要重构而将其删除,并且尚未将其放回原处。所以我的猜测是你在那里有一个扫描仪,它不能正常工作,你把扫描仪拿出来,但导入仍然存在。
Chances are if you imported it once, you'll need to use it somewhere.Before you go deleting it, remember why it was there.
如果您将其导入一次,则可能需要在某处使用它。在你删除它之前,记住它为什么在那里。
回答by Lopes_CP_619
You are not using the import java.util.Scanner
and so it says never used. You should just delete it. If you did use it though, you would need to input Scanner input = new Scanner(System.in);
after the public class.
你没有使用import java.util.Scanner
,所以它说从来没有使用过。你应该删除它。如果您确实使用了它,则需要Scanner input = new Scanner(System.in);
在公共课程之后输入。