1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NeX [460]
4 years ago
5

Write a filter that reads in a sequence of integers and prints the integers, 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 should print 1 2 1 5 1 7 1.
Computers and Technology
2 answers:
lara31 [8.8K]4 years ago
7 0

Answer:

Following is the code for filter:

public class filter

{ public static void main(String[] args)

{ int x = StdIn.readInt();

System.out.print(" " + x + " ");

while(!StdIn.isEmpty())

{ int y = StdIn.readInt();

    if(y != x)

          System.out.print(" " + y + " ");

    x = y;

    }

    }

    }

Explanation:

  • A public class filter is used.
  • The main function will accept a single argument as string[], it is also known as java command line argument.
  • Now the Stdln.readInt is used to read the integers in the sequence and store it in integer x.
  • The value stored in variable x will be printed using System.out.print
  • Now unless the Stdln.readInt gets an empty value, check each value of sequence and store in variable y.
  • If y is not equal to previous value x, print it and shift the value of y into x.
  • Repeat the loop again.

i hope it will help you!

kykrilka [37]4 years ago
4 0

Answer:

Computer

Explanation:

You might be interested in
Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The pro
galben [10]

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        int num[] = new int[51];
  5.        Scanner input = new Scanner(System.in);
  6.        System.out.print("Number of input: ");
  7.        int limit = input.nextInt();
  8.        for(int i=0; i < limit; i++){
  9.            System.out.print("Input a number (1-50): ");
  10.            int k = input.nextInt();
  11.            num[k]++;
  12.        }
  13.        for(int j=1; j < 51; j++){
  14.            if(num[j] > 0){
  15.                System.out.println("Number of occurrence of " + j + ": " + num[j]);
  16.            }
  17.        }
  18.    }
  19. }

Explanation:

The solution is written in Java.

Firstly, create an integer array with size 51. The array will have 51 items with initial value 0 each (Line 5).

Create a Scanner object and get user entry the number of input (Line 6-7).

Use the input number as the limit to control the number of the for loop iteration to repeatedly get integer input from user (Line 9-13). Whenever user input an integer, use that integer, k, as the index to address the corresponding items in the array and increment it by one (LINE 11-12).

At last, create another for loop to iterate through each item in the array and check if there is any item with value above zero (this means with occurrence at least one). If so, print the item value as number of occurrence (Line 14-17).

8 0
4 years ago
when doing a complex presentation which of the fallowing will be the best tool to begin designing your presentation
qaws [65]

but where are the option bro

7 0
2 years ago
Read 2 more answers
Xcvasdfgfdsasdfghjhgf
Cerrena [4.2K]

Well, The answer would be zxnisdnkfnxkzl since ndlsfd;gjfsdd is a forsfgfd operation. Also, the ffsldflslc is like the dfgfd. Keep that in mind when you are studying the ffsldflslc. It could be tough on the test.

3 0
3 years ago
All the answers I've got is 0, which seems strange but I'm sure I'm following this algorithm correctly.
Salsk061 [2.6K]
I think its six. im not sure but it could be another on.                                                                     

7 0
4 years ago
Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an
grigory [225]

Answer:

Explanation:

The following code is written in Java. It reads every input and checks to see if it is valid. If it is it writes it to the output file.

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

class Brainly {

           public static void main(String[] args) {

               try {

                   File myObj = new File("C:/Users/Gabriel2/AppData/Roaming/JetBrains/IdeaIC2020.2/scratches/input.txt");

                   Scanner myReader = new Scanner(myObj);

                   FileWriter myWriter = new FileWriter("C:/Users/Gabriel2/AppData/Roaming/JetBrains/IdeaIC2020.2/scratches/output.txt");

                   while (myReader.hasNextLine()) {

                       String data = myReader.nextLine();

                       int sum = 0;

                       for (int x = 0; x < 5; x++ ) {

                           sum += data.charAt(x);

                       }

                       int remainder = (sum % 10);

                       System.out.println(remainder);

                       System.out.println(data.charAt(5));

                       if (remainder == Integer.parseInt(String.valueOf(data.charAt(5)))) {

                           System.out.println("entered");

                           try {

                               myWriter.write(data + "\n");

                               System.out.println("Successfully wrote to the file.");

                           } catch (IOException e) {

                               System.out.println("An error occurred.");

                               e.printStackTrace();

                           }

                       }

                       sum = 0;

                   }

                   myWriter.close();

                   myReader.close();

               } catch (FileNotFoundException e) {

                   System.out.println("An error occurred.");

                   e.printStackTrace();

               } catch (IOException e) {

                   e.printStackTrace();

               }

           }

       }

3 0
3 years ago
Other questions:
  • Which of the following were input devices for early portable computers?
    6·1 answer
  • An algorithmic function that takes an input message of arbitrary length and returns an output of fixed-length is called a(n) ___
    10·1 answer
  • Authorization is a set of rights defined for a subject and an object. They are based on the subject’s identity.a. Trueb. False
    9·1 answer
  • Is it better to meet online or offline<br> (Please answer QUICK)<br><br> Thanks :')
    5·2 answers
  • Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "
    9·1 answer
  • Over a TCP connection, suppose host A sends two segments to host B, host B sends an acknowledgement for each segment, the first
    6·1 answer
  • Suppose you have four 500 MB hard drives plus one 2 GB flash drive. How many GB of capacity is this overall?
    12·1 answer
  • For as long as you can remember, you've never been able to get a taco on Tuesday at your local taco truck. The lines are always
    8·1 answer
  • Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It shou
    7·1 answer
  • When you download a file from the internet where should you go to find it?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!