我的代码有问题,希望有人能看到我缺少的东西。我的代码如下:
import java.io.IOException;
class Boat{
String boatName = (" ");
boolean sailUp = false;
}
public class Project2{
public static void main(String[] args){
System.out.println("\n");
Boat[] boatArray;
boatArray = new Boat[args.length];
for(int i = 0 ; i < args.length ; ++i){
boatArray[i] = new Boat();
}
for(int j = 0 ; j < args.length ; ++j){
boatArray[j].boatName = args[j];
}
for(int k = 0 ; k < args.length ; ++k){
String firstLetter = boatArray[k].boatName.substring(0, 1);
if(firstLetter == ("B")){
boatArray[k].sailUp = true;
}else if(firstLetter == ("C")){
boatArray[k].sailUp = true;
}else if(firstLetter == ("N")){
boatArray[k].sailUp = true;
}else{
boatArray[k].sailUp = false;
}
}
for(int l = 0 ; l < args.length ; ++l){
System.out.println("\nThe " + boatArray[l].boatName + " is ready to sail...");
if(boatArray[l].sailUp == false){
System.out.println("\n\tbut the sail is down, raise the sail!");
}else if(boatArray[l].sailUp == true){
System.out.println("\n\tthe sail is up, ahead full!");
}
}
}
}
我想要以下输出:
C:\Documents and Settings>java Project2 Enterprise Challenger Discovery Nimitz
企业已准备好启航...
but the sail is down, raise the sail!
挑战者号已准备好启航……
the sail is up, ahead full!
发现号准备启航...
but the sail is down, raise the sail!
尼米兹号准备启航...
the sail is up, ahead full!
但我明白了:
C:\Documents and Settings>java Project2 Enterprise Challenger Discovery Nimitz
企业已准备好启航...
but the sail is down, raise the sail!
挑战者号已准备好启航……
but the sail is down, raise the sail!
发现号准备启航...
but the sail is down, raise the sail!
尼米兹号准备启航...
but the sail is down, raise the sail!
为什么第三个循环没有重置帆状态?