• 找水王


    package test2;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    
    
    
    
    public class ShuiWang {
        public static void main(String[] args) throws IOException {
            find();
        }
    
        public static void find() throws IOException {
            BufferedReader br = new BufferedReader(new FileReader("sw.txt"));
            String s,s1 = null,s2 = null,shuiwang = null;
            int i=1;
            while((s = br.readLine()) != null) {
                s1 = s;
                if(s2 == null) {
                    s2 = br.readLine();
                }
                System.out.println("------------------------------------------");
                System.out.println("第" + i++ + "次比较");
                System.out.println("s1:" + s1);
                System.out.println("s2:" + s2);
                if(s2 != null) { 
                    if(s1.compareTo(s2) != 0) 
                        s2 = null;
                    else                      
                        shuiwang = s2;
                }else {
                    shuiwang = s1;
                }
                System.out.println("记录id:" + shuiwang);
            }
            if(shuiwang == null)
                shuiwang = s2;
            System.out.println("
    水王id为:" + shuiwang);
            br.close();
        }
    
    }
    

      

    package test2;

    import java.io.BufferedReader;

    import java.io.FileReader;

    import java.io.IOException;

     

     

     

     

    public class ShuiWang {

        public static void main(String[] args) throws IOException {

            find();

        }

     

        public static void find() throws IOException {

            BufferedReader br = new BufferedReader(new FileReader("sw.txt"));

            String s,s1 = null,s2 = null,shuiwang = null;

            int i=1;

            while((s = br.readLine()) != null) {

                s1 = s;

                if(s2 == null) {

                    s2 = br.readLine();

                }

                System.out.println("------------------------------------------");

                System.out.println("" + i++ + "次比较");

                System.out.println("s1:" + s1);

                System.out.println("s2:" + s2);

                if(s2 != null) {

                    if(s1.compareTo(s2) != 0)

                        s2 = null;

                    else                      

                        shuiwang = s2;

                }else {

                    shuiwang = s1;

                }

                System.out.println("记录id:" + shuiwang);

            }

            if(shuiwang == null)

                shuiwang = s2;

            System.out.println(" 水王id:" + shuiwang);

            br.close();

        }

     

    }

  • 相关阅读:
    C#跨窗体操作
    搞IT的不如去养鸡养猪了
    C# 委托实例(跨窗体操作控件)
    FastReport 自定义页长
    SQL 根据一个表更新另一个表的内容
    Delphi中用ADOQuery实现主从表的例子(转)
    旅行的意义
    嘉州影院的网址
    纯粹的人
    Delphi中流的使用:压缩与解压缩(TCompressionStream、TDecompressionStream)
  • 原文地址:https://www.cnblogs.com/xiatian21/p/13086797.html
Copyright © 2020-2023  润新知