找水王

package Test;

public class t {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.print("原始数据:");
        char[] a={'1','2','2','3','2','1','2','2','2','1'};
        //char[] a={'1','3','3','3','2','3','3','3','2','3','1'};
        //char[] a={'1'};
        //char[] a={'1','3','3'};
        int n=a.length;
         for(int j=0;j<n;j++){
               System.out.print(a[j]+" ");
               }
         System.out.println();
        System.out.print("变化过程:");
        int i=0;
       while(i<n){
       if(i+1>=n){break;}
       else{
        if(a[i]==a[i+1]){
            i++;
        }
        else{
            a[i]='*';
            a[i+1]='*';
            i+=2;
        }//if...else...
      }
            }
       
       System.out.println();
       for(int j=0;j<n;j++){
           System.out.print(a[j]+" ");
       }
       System.out.println();
       System.out.print("找出结果:");
       for(int j=0;j<n;j++){
            if(a[j]!='*'){
               System.out.println(a[j]);
               break;
           }
       }

    }
}

 

 

结果截图:

 

posted @ 2017-04-19 22:28  陶雨洁  阅读(210)  评论(0编辑  收藏  举报