Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Cody Bank JAVA program Squish

Tagged: , ,

Viewing 0 reply threads
  • Author
    Posts
    • #1233
      Abhishek TyagiAbhishek Tyagi
      Keymaster

        JAVA Squish Program Problem Statement- Write a program Squish that reads in a sequence of integers
        from standard input and prints out the integers, but removing repeated values that appear consecutively. For example,
        if the input is
        1 2 2 1 5 1 1 7 7 7 7 1 1 1 1 1 1 1 1 1
        your program prints
        1 2 1 5 1 7 1
        For simplicity, don’t add a space or newline at the end. You may assume there is at least one input.

        Code-

        • `public class Squish {
              public static void main(String[] args) {
              // get first value and print
                int value = StdIn.readInt();
                StdOut.print(value);
                // read in remaining values
                while (!StdIn.isEmpty()) {
                    int next = StdIn.readInt();
                    // only print if different
                    if (value != next) {
                      value = next;
                      System.out.print(” ” + value);
                      }
                    }
                  }
           }`
    Viewing 0 reply threads
    • You must be logged in to reply to this topic.