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

正常循环

 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();
}
}
}
上一篇:[LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项


下一篇:leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法