about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/4/LongestRun.java
blob: 74c18c7587178044b850a77dfdbe87d70839bfff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;

class LongestRun
{
  public static void main(String... args)
  {
    var scanner = new Scanner(System.in);
    Integer number = null;
    Integer length = null;
    Integer n = null, len = null;

    while (scanner.hasNextInt())
      {
        Integer i = scanner.nextInt();
        if (i == n)
          {
            len++;
            continue;
          }
        if (length == null || len > length)
          {
            number = n;
            length = len;
          }
        n = i;
        len = 1;
      }
    System.out.printf("Longest run: %d consecutive %d\n", number, length);
  }
}