answer.
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
Alinara [238K]
2 years ago
7

python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i

s considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7. Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. In this case,3 would be printed. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.
Computers and Technology
1 answer:
Vika [28.1K]2 years ago
7 0

int firstNumber,secondNumber = -1, duplicates = 0;

do {

cin >> firstNumber;

if ( secondNumber == -1) {

secondNumber = firstNumber;

}else {

if ( secondNumber == firstNumber )

duplicates++;

else

secondNumber = firstNumber;

}

} while(firstNumber > 0 );

cout << duplicates;

You might be interested in
CodeLab Question
castortr0y [4]

Answer:

Idk the language of code but here is how it would be done in python

myAlarm():

   arm = True

   code = "secret message"

myAlarm()

main():

deactivate = input(">>> ")

if deactivate = myAlarm.code:

  arm = False

Im still a little confused on the question.

(I am a game designer and I code daily)

3 0
1 year ago
Write a class for a Cat that is a subclass of Pet. In addition to a name and owner, a cat will have a breed and will say "meow"
fenix001 [56]

Answer:

The Java class is given below with appropriate tags for better understanding

Explanation:

public class Cat extends Pet{

  private String breed;

 public Cat(String name, String owner, String breed){

      /* implementation not shown */

      super(name, owner);

      this.breed = breed;

  }

  public String getBreed() {

      return breed;

  }

  public void setBreed(String breed) {

      this.breed = breed;

  }

  public String speak(){ /* implementation not shown */  

      return "Purring…";

  }

}

8 0
1 year ago
Write a function string middle(string str) that returns a string containing the middle character in str if the length of str is
Katen [24]

Answer:

function getMiddle(s) {

return s.length % 2 ? s.substr(s.length / 2, 1) : s.substr((s.length / 2) - 1, 2);

}

// I/O stuff

document.getElementById("submit").addEventListener("click", function() {

input = document.getElementById("input").value;

document.getElementById("output").innerHTML = getMiddle(input);

});

Explanation:

// >>> is an unsigned right shift bitwise operator. It's equivalent to division by 2, with truncation, as long as the length of the string does not exceed the size of an integer in Javascript.

// About the ~ operator, let's rather start with the expression n & 1. This will tell you whether an integer n is odd (it's similar to a logical and, but comparing all of the bits of two numbers). The expression returns 1 if an integer is odd. It returns 0 if an integer is even.

// If n & 1 is even, the expression returns 0.

// If n & 1 is odd, the expression returns 1.

// ~n & 1 inverts those two results, providing 0 if the length of the string is odd, and 1 if the length of the sting is even. The ~ operator inverts all of the bits in an integer, so 0 would become -1, 1 would become -2, and so on (the leading bit is always the sign).

// Then you add one, and you get 0+1 (1) characters if the length of the string is odd, or 1+1 (2) characters if the length of the string is even.

6 0
1 year ago
Assume your friend just sent you 32 bits of pixel data (just the 0s and 1s for black and white pixels) that were encoded after s
lara31 [8.8K]

Answer:

your friend just sent you 32 bits of pixel data (just the 0s and 1s for black and white pixels) that were encoded after sampling an image. Choose the two statements that are true.

------------------

The 32 bits of pixel data is enough to produce the image using the widget. Nothing else is needed.

------------------------

The digital image would be an exact copy of the analog image.

-----------------------------The correct width and height must be input into the pixelation widget to produce the image.

---------------------------The fact that only 32 bits were used to represent the image indicates relatively large sample squares were used. The digital image may vary from the analog image significantly

Explanation:

3 0
2 years ago
Two middle-order batsmen are compared based on their performance in their previous cricket match.
Zolol [24]
How many points is this for
5 0
2 years ago
Other questions:
  • CAPTCHAs can be used as a form of signature to create a valid contract in e-commerce. True False
    6·2 answers
  • A two-dimensional array can have elements of ________ data type(s).
    7·1 answer
  • Dr. Robbins wants to know if there are different opinions regarding the value of public school education between Native American
    11·1 answer
  • JAVAThe method longestStreak is intended to determine the longest substring of consecutive identical characters in the parameter
    7·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    5·1 answer
  • Mike has never used a slide software before, but he needs to create a presentation by the end of the week. what recourse would b
    8·1 answer
  • Interpretations of​ Moore's law assert​ that:
    13·1 answer
  • A triangular number is a number that is the sum of the integers from 1 to some integer n. Thus 1 is a triangular number because
    11·1 answer
  • array of String objects, words, has been properly declared and initialized. Each element of words contains a String consisting o
    11·1 answer
  • Earlier in the day, you created a user account for Brenda Cassini (bcassini). When she tries to log in, she can't. You realize t
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!