how to continue run the java programme

2007-03-26 7:40 am
when i run the java programme, the latest, we want to continue run it, how to work.
........
System.out.println("Do you want to continue?(y,n)");
String input_4 = keyboard.readLine();
if (input_4 == y) ?????
// there is a wrong in here
System.out.println("you want to continue!");

else
System.out.println("Thank you!");

but it does'n run! what is wrong??

thank you!!

回答 (1)

2007-03-26 8:34 am
✔ 最佳答案
Since you did not write how you defined keyboard, I assume
keyboard is:
import java.io.*;
....

BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

You need to catch IOException when reading line:
In order to match the content of input_4 with another string, you need to do this instead:
try {
String input_4 = keyboard.readLine();
if (input_4.equals("y"))
System.out.println("you want to continue!");
else
System.out.println("Thank you!");
} catch (IOException e) {
// Exception handler
}


收錄日期: 2021-04-13 15:37:05
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070325000051KK06204

檢視 Wayback Machine 備份