[20160730]while 条件的死循环和正常循环对比

时间:2022-07-29 12:38:35

正常循环

 import java.io.*;
import java.util.*; public class MyPrintStreamTest3{
public static void main(String[] args) {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );
String s = null; try
{
PrintWriter log = new PrintWriter( new FileWriter("D://javalearning//MYIO//log4j.txt",true) );
while((s = br.readLine())!=null){
if (s.equalsIgnoreCase("exit")) break;
System.out.println(s.toUpperCase());
log.println("--------");
log.println(s.toUpperCase());
log.flush();
}
log.println("=="+new Date()+"==");
log.flush();
log.close(); }
catch (IOException e)
{
e.printStackTrace();
}
}
}

死循环

 import java.io.*;
import java.util.*; public class MyPrintStreamTest3{
public static void main(String[] args) {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );
String s = null; try
{
PrintWriter log = new PrintWriter( new FileWriter("D://javalearning//MYIO//log4j.txt",true) );
s = br.readLine();
while(s!=null){
if (s.equalsIgnoreCase("exit")) break;
System.out.println(s.toUpperCase());
log.println("--------");
log.println(s.toUpperCase());
log.flush();
}
log.println("=="+new Date()+"==");
log.flush();
log.close(); }
catch (IOException e)
{
e.printStackTrace();
}
}
}