首页 > 代码库 > HW6.30

HW6.30

技术分享

 

 1 import java.util.Scanner; 2  3 public class Solution 4 { 5     public static void main(String[] args) 6     { 7         Scanner input = new Scanner(System.in); 8         System.out.print("Enter the length of the list: "); 9         int length = input.nextInt();10         int[] list = new int[length];11         for(int i = 0; i < length; i++)12             list[i] = input.nextInt();13         input.close();14         System.out.println(isConsecutiveFour(list));15     }16 17     public static boolean isConsecutiveFour(int[] values)18     {19         if(values.length < 4)20             return false;21         for(int i = 0; i < values.length - 4; i++)22         {23             if(values[i] == values[i + 1] && values[i] == values[i + 2] && values[i] == values[i + 3])24                 return true;25         }26         return false;27     }28 }

 

HW6.30