TheBulgarianWolf

Longest Sequence of Increasing Numbers

Mar 17th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.print("Enter thе amount of numbers: ");
  7.         int n = Integer.parseInt(sc.nextLine());
  8.         int countCurrentLongest = 0;
  9.         int countLongest = 0;
  10.         int aPrev = 0;
  11.         int num = 0;
  12.         for(int i =0;i<n;i++){
  13.             num = Integer.parseInt(sc.nextLine());
  14.            
  15.             if(num > aPrev){
  16.                 countCurrentLongest++;
  17.             }
  18.             else{
  19.                 countCurrentLongest = 1;
  20.             }
  21.            
  22.             if(countCurrentLongest > countLongest){
  23.                 countLongest = countCurrentLongest;
  24.             }
  25.             aPrev = num;
  26.         }
  27.        
  28.         System.out.println("The longest sequence of increasing numbers is: "countLongest);
  29.     }
  30. }
Add Comment
Please, Sign In to add comment