import java.util。*;公共类随机{
public static void main(String[] args) {
// TODO Auto-generated method stub
try (Scanner number = new Scanner(System.in)) {
if (number.nextLine().startsWith("J") && number.nextLine().length() > 3 )
{
System.out.println("Your name is over 3 letters and starts with the letter J!");
}
else if (number.nextLine().length() < 3)
{
System.out.println("Your name is too short!");
}
else if (number.nextLine().length() > 10)
{
System.out.println("Your name is too long!");
}
}
}
}
只需将其添加到try块的开始(声明变量)之后:
String numberString = number.nextLine()
然后在您的条件下用变量替换number.nextLine()
!