コードに問題があり、誰かが不足しているものを見つけてくれることを願っています。私のコードは次のとおりです。
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!
3 番目のループで帆の状態がリセットされないのはなぜですか?