我想说如果你输入一个字符,它会这样做;否则,如果扫描仪输入== 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