无法打印出结果

时间:2013-05-18 18:23:51

标签: java loops

我尝试打印出文本:Aloha但它没有打印任何内容,如果我删除文本正上方的循环,它打印。有人可以帮我解释一下吗?如果我想保持循环(对于(s = 5; s <0; - s)),我该如何使其工作?感谢

import java.io.*;

public class Email13 {
    static boolean isValidEmailCharacter(char c){
        boolean result = false;
        if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||(c=='.')||(c=='-')||(c=='+'))
            result = true;
        return result;
    }

    public static void main(String[] args) throws Exception{
        BufferedReader cin, fin;
        cin = new BufferedReader(new InputStreamReader(System.in));
        //Description
        System.out.println("Programmer: Minh Nguyen");
        System.out.println("Description: This program is to start the final project.");
        System.out.println();    

        String nameIn, nameOut, deIn, deOut;
        nameIn="";
        nameOut="";
        deIn = "fileContainingEmails.txt";

        System.out.print("Enter input filename [default:" + deIn + "]: ");
        nameIn = cin.readLine();

        if(nameIn.compareTo("")==0){
            nameIn = deIn;
            deOut = "copyPasteMyEmails.txt";
            System.out.print("Enter output filename [default:" + deOut + "]: ");
            nameOut = cin.readLine();
        if(nameOut.compareTo("")==0)
           nameOut = deOut;
        }
        else if(nameIn.compareTo("")>0){
            deOut = nameIn;
            System.out.print("Enter output filename [default:" + deOut + "]: ");
            nameOut = cin.readLine();
            if(nameOut.compareTo("")==0)
                nameOut = nameIn;
       }
       fin = new BufferedReader(new FileReader(nameIn));
       //Read the input file
       while(true){
           if(!fin.ready()) break;
           String lineFromFile;
           lineFromFile = fin.readLine();
           int s, e, hasDot, count;
           count = 0;
           for (int i = 0; i < lineFromFile.length(); i++) // for each char in the string...           
           {
               if(lineFromFile.charAt(i)=='@'){                        
                   for(s=5; s<0;--s)
                       System.out.println("Aloha");                                                        
              }
          }
      }
      fin.close();

      PrintWriter fout;
      fout = new PrintWriter(new FileWriter(nameOut));
      fout.close();        
      }
 }

1 个答案:

答案 0 :(得分:2)

s不小于0,因此它永远不会进入该循环

for(s=5; s<0;--s)

只是做到了

for(s=5; s>0;--s)