我正在对我的 MyZoo 类使用扫描仪方法来读取制表符分隔的文本文件,如下所示:
import shipment of April 12, 2007
# tab separated data
Bird Golden Eagle Eddie
Mammal Tiger Tommy
Mammal Lion Leo
Mammal Elephant Eddie
Bird Parrot Polly
# last one next
Reptile Cobra Colin
我已经分解了三个数据列: Type, Species and name
。
但是第一行数据不是动物数据,因此我在while循环之前使用“ scanner.nextLine”忽略它,但是我仍然希望将其打印到终端,只是不会被读取为动物数据。
代码:
scanner.nextLine();
while(scanner.hasNextLine())
{
String type = scanner.next();
String species = scanner.next();
String name = scanner.next();
System.out.println(scanner.nextLine());
System.out.println(type + " " + species + " " + name);
scanner.nextLine();
addAnimal( new Animal(species, name, this) );
String line = scanner.nextLine();
if(line.startsWith("#"))
{
continue;
}
else
{
scanner.nextLine();
addAnimal( new Animal(species, name, this) );
}
}
答案 0 :(得分:3)
只需更改您最初的 <div class="classB" style="background-color: black">
<div>Box C</div>
</div>
调用即可将其打印出来:
nextLine