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
valentinak56 [21]
3 years ago
14

Assume that someone dictates you a sequence of numbers and you need to write it down. For brevity, he dictates it as follows: fi

rst says the number of consecutive identical numbers and then says the number itself. E.g. The sequence 1 1 3 3 3 2 2 2 2 14 14 14 11 11 11 2 will be dictated as "Two ones, three threes, four twos, three fourteens, three elevens, one two", so you will write down the sequence 2 1 3 3 4 2 3 14 3 11 1 2. The challenge is to write the program which compresses the given sequence using this approach.
Computers and Technology
1 answer:
hram777 [196]3 years ago
4 0

Answer:

Answer is in java language

Explanation:

Java Code

public class Compress{

public static void main(String []args){

      int[] array=new int[]{1 ,1 ,3 ,3, 3, 2, 2, 2, 2, 14, 14, 14, 11, 11, 11, 2};

      int currentNumber=array[0];

      int count=1;

      for(int i=1;i <array.length;i++){

          if(currentNumber != array[i]){

              System.out.print(count+" " +currentNumber+" ");

              currentNumber=array[i];

              count=1;

          } else{

              count++;

          }

      }

      System.out.print(count+" " +currentNumber+" ");

  }

}

Code Explanation

First create two variables which will hold the current number and its count and then iterate over every element in array. If current index value is different from currentNumber variable then display the previous calculated number value and its count and then change the value to current index of array.

At the end display the last calculated value.

Example

Answer will look like below

2 1 3 3 4 2 3 14 3 11 1 2

You might be interested in
What is meant by versatility in terms of features of computer?​
scoray [572]

Answer:

Versatility refers to the capability of a computer to perform different kinds of works with same accuracy and efficiency.

Explanation:

thank me later

3 0
3 years ago
Read 2 more answers
Create a java class for Bank Accounts with these public String attributes: ownerName, acctNbr and these private double attribute
Readme [11.4K]

Answer:

public class BankAccounts

 {

   public String ownerName;

   public String acctNbr;

   private double debits;

   private double credits;

   public BankAccounts(String ownerNm, String acNum)

  {

    debits = 0;

    credits = 0;

    ownerName = ownerNm;

    acctNbr = acNum;

  }

public void addDebit(double debitAmt)

  {

    if(credits > (debits + debitAmt))

      debits = debits + debitAmt;

    else

      System.out.println("Insufficient balance");

}

   public void addCredit(double creditAmt)

  {

    credits = credits + creditAmt;

  }

public double getBalance()

  {

    double balance = 0;

    if((credits - debits) > 0)   // return the value if there is actually some balance left.

      balance = credits - debits;

    return balance;   //returns 0 if credits are lesser or equal to debits

  }

 }

Explanation:

Here class name is <em>BankAccounts </em>which can be used to create a new bank account whenever any user wants to open a bank account. This class will help to track any new account opening, debits and credits operations carried out on that account.

We have a constructor here, which accepts 2 arguments i.e. Bank account <em>Owner Name</em> and <em>Account Number</em>. The constructor also sets the values of <em>debits </em>and <em>credits</em> as 0.

The methods <em>addDebit()</em>, <em>addCredit()</em> and <em>getBalance()</em> help to perform Debit and Credit operations on the account.

NOTE: The method <em>getBalance()</em> returns a positive value only when credits are greater than debits.

The method <em>addDebits()</em> can add debits only as the condition that the credits are greater than the resultant debits.

The code for class <em>BankAccounts</em> is hereby attached.

Download java
4 0
3 years ago
As a final lesson to her team, Katie shows them a job that has already been preflighted and is now getting ready to be sent to t
Vsevolod [243]

Answer:

Printed

Explanation:

The job was finished and sent to the printer. In the printer, you have to waite to be printed

5 0
3 years ago
A and B have same output or not? A B x=0 x=0 do do x&lt;3 x=x+1 x=x+1 print x print x while x&lt;3 while
katen-ka-za [31]

Answer:

A and B have different output:

A output will be 1

B output will be 123

Explanation:

A

X = 0

do x < 3

x = x+1

print x

while

B

X = 0

do x = x+ 1

print x

while x < 3

For statement A the condition statement which suppose to be after "while" is not set therefore the value of x will be printed.

For statement B the condition statement is set "x < 3" in front of "while" thereby result in iteration until the condition is false.

Statement A output will be 1

Statement B output will be 123

6 0
4 years ago
Select the correct answer from each drop-down menu. Which IF formulas are valid? _____ and _____ are valid IF formulas.
Lyrx [107]

Answer:

=IF(D3>50; E3; F3) AND =IF(A1>60;"Pass";"Fail")

Explanation:

An IF structure is built following this pattern:

IF(TEST;IFTRUE;IFFALSE)

These are the only options in the given drop-down menus what comply with this pattern.  All others are not following this pattern.

The computer will do the test and if the result is true will apply the IFTRUE value, otherwise will apply the IFFALSE value.

4 0
4 years ago
Other questions:
  • Peripherals can be used to output information.<br> True<br> False
    9·2 answers
  • Emilio is reviewing the data he collected from historical records about immigration in the united states. He decides to create a
    5·1 answer
  • The replacer parameter of the stringify method accepts a/an ______________ or an array.
    15·1 answer
  • True or false: when an ospf route sends its link state information, it is sent only to those nodes directly attached neighbors.
    14·1 answer
  • What property must be set on a menu item to have the user activate that option by pressing Ctrl C on the keyboard
    11·1 answer
  • Which storage is faster than secondary storage​
    14·2 answers
  • Place the steps for attaching a file to a message in order from top to bottom.
    12·1 answer
  • Merging refers to dividing a single cell into multiple cells. *TrueFalse
    14·1 answer
  • is the practice of using the internet to provide healthcare without going to a doctor’s office or hospital.
    15·1 answer
  • Which discipline focuses on the design of computer hardware?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!