其中这个boolean是给里面的三目运算符赋值,不是给while循环赋值
package day20;
import javafx.scene.input.DataFormat;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CharBye{
public static void main(String[] args) throws Exception{
PrintStream ps = new PrintStream(new FileOutputStream("e:/a.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//其中这个boolean是给里面的三目运算符赋值,不是给while循环赋值,以免错误,导致循环结束
boolean flag=true;
while(true){
Date d = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// System.out.println(df.format(d));
System.out.println(df.format(d)+"请"+(flag?"一号:":"二号:")+"输入发送内容:");
String ss = br.readLine();
if("bye".equalsIgnoreCase(ss)){
System.out.println("聊天结束");
break;
}
// else {
Date dd = new Date();
SimpleDateFormat ddf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ps.println(ddf.format(dd)+(flag?"一号:":"二号:")+ ss);
flag = !flag;
//}
}
ps.close();
br.close();
}
}