我在Eclipse中編碼,所以我的一些錯誤消息可能會不同我試圖打印一條消息,所以如果沒有字符'a '在String s3中,那麼它會告訴用戶嘗試另一行代碼。我的語句的if部分沒有問題,但其他部分是。我似乎無法弄清楚如何修正我的語句,所以如果有人能夠幫助,謝謝!試圖操縱Java中的字符串,並繼續獲得「」布爾值「
//print the index of the last occurrence of the character 'a' in string s3
if (s3.indexOf('a')>= 0 {
System.out.println("The first occurrence of the character 'a' in both strings is at index " + s3.indexOf('a'));
}
else (s3.indexOf('a') > 0)
System.out.println("There is no occurrence of the character 'a' in either string.");
}
開始通過在第一行中添加近距離括號,所以代碼將被編譯。 – Andreas