File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ /**
4+ * Write a program that reads an array of ints and outputs the length of the longest sequence in strictly ascending order.
5+ * Elements of the sequence must go one after another. A single number is assumed to be an ordered sequence with the length = 1.
6+ */
7+ public class longestAscendingSequence {
8+
9+ public static void main (String [] args ) {
10+ Scanner scanner = new Scanner (System .in );
11+ int tam = scanner .nextInt ();
12+ int [] numbers = new int [tam ];
13+
14+ for (int i = 0 ; i < numbers .length ; i ++) {
15+ numbers [i ] = scanner .nextInt ();
16+ }
17+
18+ int maxTmp = 0 ;
19+ int count = 1 ;
20+
21+ for (int i = 0 ; i < numbers .length - 1 ; i ++) {
22+ if (numbers [i ] < numbers [i + 1 ]) {
23+ ++count ;
24+ } else {
25+ if (count > maxTmp ) {
26+ maxTmp = count ;
27+ }
28+ count = 1 ;
29+ }
30+ }
31+
32+ int max = Math .max (count , maxTmp );
33+
34+ System .out .println (max );
35+
36+ scanner .close ();
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments