Water king Programming

Design ideas:

First, a name is first recorded data, sum is set to 1, and if the back compared to the same sum plus 1, then compare the latter, or minus 1. Carried out before making a comparative sum worth judgment, if it is 0, then re-defined name for the temporary water king, otherwise continue in accordance with the previous method.

Source code is as follows:

package water;

public class water {
    public static void main(String [] args) {
        int sum=0;
        int name=0;
        int num[] = {2,2,2,2,2,2,1,1,1,1};
        for(int n=0;n<9;n++) {
            if(sum==0) {
                name=num[n];
                sum=1;
            }
            if(name!=num[n+1]) {
                sum--;
            }the else { 
                SUM ++ ;     
            } 
        } 
        of System.out.print ( "Water Wang:" + name); 
    } 
}

Screenshot below:

 

Guess you like

Origin www.cnblogs.com/hwh000/p/10951433.html