maxpigreco

FiltraConsecutivi.java

Mar 13th, 2022 (edited)
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. /* *****************************************************************************
  2.  *  Name:              maxpigreco
  3.  ******************************************************************************* */
  4.  
  5. public class FiltraConsecutivi {
  6.     public static void main(String[] args) {
  7.  
  8.         // Caso senza input
  9.         if (StdIn.isEmpty()) {
  10.             StdOut.println("Nessun valore inserito");
  11.             return;
  12.         }
  13.  
  14.         int x = StdIn.readInt();
  15.         String filter = Integer.toString(x);
  16.  
  17.         while (!StdIn.isEmpty()) {
  18.             int y = StdIn.readInt();
  19.             if (y != x) {
  20.                 filter += " " + Integer.toString(y);
  21.                 x = y;
  22.             }
  23.         }
  24.         StdOut.print(filter);
  25.     }
  26. }
  27.  
  28.  
  29. /*
  30.     input: 1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1 CTRL+D (one per line)
  31.     output: 1 2 1 5 1 7 1
  32. */
  33.    
Add Comment
Please, Sign In to add comment