0
任何人都可以幫助我解決此問題,但我一直在收到錯誤消息。 我主要關心如何打印這些線路輸出「打印出了名的長度如果超過10且小於20個字符長,並且在名稱中第三個字母」打印出長度超過10個字符且長度小於20個字符的名稱,並在名稱中輸入第三個字母
public static void main(String[] args) {
System.out.println("Class activity");
Scanner scn = new Scanner(System.out);
System.out.println("Please enter your name");
String name = scn.nextDouble();
Main.processName(name);
}
/**
* Print out the length of the name if it is more than 10 and less than 20 characters long, and the third letter in the name
*/
private int processname(String name) {
int len = name.len();
if (len > 10 | len < 20) {
System.out.println("Wow," + name + " that name is between 10 and 20 characters long!");
}
char thirdLetter = name.charAt(3);
System.out.println("Your name has " + len + " letters and the second letter is " + thirdLetter);
}
邏輯或是||,不是|。 –