import java.util.Scanner; public class Q3 { public static int longestRun(float[] sequence) { int length = 1, maxLength = 1; if (sequence == null || sequence.length == 0) return 0; for (int i = 0; i < sequence.length - 1; i++) { if (sequence[i] == sequence[i + 1]) length++; else { if (maxLength < length) maxLength = length; length = 1; } } //in case the longest run comes at the tail end of the sequence if (maxLength < length) maxLength = length; return maxLength; } public static void main(String[] args) { String strNumbers; float[] numberArray; Scanner in = new Scanner(System.in); System.out.println("Please input a list of numbers separated by spaces:"); strNumbers = in.nextLine(); if (strNumbers.trim().isEmpty()) { System.out.println("The sequence is empty!"); return; } String[] strNumberArray = strNumbers.split("\\s+"); numberArray = new float[strNumberArray.length]; for (int i = 0; i < strNumberArray.length; i++) numberArray[i] = Float.parseFloat(strNumberArray[i]); System.out.println("Result: " + longestRun(numberArray)); } }