我想說如果你輸入一個字符,它會這樣做;否則,如果掃描儀輸入== null做,而不是。我沒有收到任何語法錯誤,我只需要知道如何說出這一點,以便如果你不輸入任何字符並按下ENTER鍵,那麼它將會進入我的默認設置。 這是我到目前爲止。掃描儀輸入== null?
Shape sq = new Square(10);
System.out.println("Choose character to fill your shape. A-Z, a-z, ! # $ % & () * + Press ENTER.");
characterChoiceSquare = input.next();
if(characterChoiceSquare == input.next())
{
for(int m = 0; m < shapeChars.length; m++)
}
{
if(characterChoiceSquare.equals(shapeChars[m]));
{
char[] c1 = characterChoiceSquare.toCharArray();
char[] shapeCharacter = new char[sq.getSizeInt()];
for(int i = 0; i < sq.getSizeInt(); i++)
{
shapeCharacter[i] = c1[0]; // repeat the char input to fit shapeString
}
string = String.valueOf(shapeCharacter); //assign the value of the arraylist to shapeString
shapeString += string + "\n";
System.out.print(shapeString);
}
}
}
else if(characterChoiceSquare == null)
{
System.out.print(sq.displayCharacters());
}
你可以使用.isEmpty()作爲條件時,而不是僅僅打流入使用不輸入任何內容。 –
我的if - else語句沒有被用在我的代碼中。這確實給了我錯誤。到目前爲止,沒有if-else的想法,它會打印這兩個選項。也許如果 - 其他不是這樣。但想法是選擇一個字符或去默認這是隨機字符形狀相同 – StephS
你的意思是如果(scanner.isEmpty())? – StephS