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
zavuch27 [327]
3 years ago
6

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 is consi

dered 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. That is, stdin = new Scanner(System.in); is given.
Computers and Technology
1 answer:
Darya [45]3 years ago
3 0

// Variable to keep track of array size

int length = 0;

// Array itself

int array[] = {};

// while loop will take input in the array until a negative number is entered

while(input>=0){

stdin = new Scanner(System.in);

array[length] = stdin;

length +=1;

}

// int variable to terminate while loop

int i =0;

// keep track of index of output array

int y =0;

while(arr[i] != length){

// making output array

int output[]={}; bool flag;

// put the element in out put array considering if it the desired one

output[y] = array [i];

// Now check if it was the desired?

for(int z=1;z<=length;z++){

if(array[i+z]!=output[y]){

 flag = true;

}

else

{

 output[y]=0;

 y+=1;

}

if(array[i+z+1]=output[y] && flag == true){

output[y] = array[i];

y+=1;

}

}

//output the array

for(int o=0;o<y;o++)

System.out.println(output[o];

You might be interested in
Implement a function named largerThanN that accepts three arguments: an array of type int, the size of the array of type int and
levacccp [35]

Answer:

import java.util.Scanner;

public class NewArray {

//Main Method begins here

   public static void main(String[] args) {

   int [] numbers = {30,20,50,2,-1,44,3,12,90,32}; //The given array

   Scanner in = new Scanner(System.in);

       System.out.println("enter a number");

       int n = in.nextInt(); //Receive the number from the user

       //Calling the method largerThanN

       largerThanN(numbers, numbers.length,n);

   }

//The method largerThanN begins here

   public static void largerThanN(int []intArray, int arraySize, int n){

       for(int i = 0; i < intArray.length; i++){

           if(intArray[i] > n){

               System.out.println(intArray[i]);

           }

       }

   }

}

Explanation:

Uisng the Java prograamming language the solution is provided above.

Please see the comments within the code for detailed explanation

The key logic within the method largerThanN () is using a for loop to iterate the entire array. Within the for loop use an if statement to compare each element with the the number n entered by the user

6 0
3 years ago
A design was operating at a maximum clock frequency of f and the clock had no jitter. if the clock started to have jitter of t s
docker41 [41]
A design was operating at a maximum clock frequency of f and the clock had no jitter. if the clock started to have jitter of t secs, what will be the new frequency?
4 0
3 years ago
Advantages of desktop publishing over traditional methods include       
Licemer1 [7]
From what my teacher taught us it would be c.
6 0
3 years ago
A victimless crime is committed when
Ksju [112]
Someone downloads a pirated song or video a copyrighted image is used without permission and a person downloads and uses pirated software.
3 0
2 years ago
What does gif stand for in computer terms?
SSSSS [86.1K]
<span>GIF stands for Graphics Interchange Format</span> which was released by CompuServe in 1987. The Graphics in GIF is why some people argue against it's originally intended pronunciation as "jif" (like the peanut butter) 
4 0
3 years ago
Other questions:
  • In Python, if var1 = “Happy” and var2= “Birthday” and var3 = (var1+var2) *2, then var3 stores the string
    15·1 answer
  • A cell reference that has only one $ is referred to as a(n) ____ cell reference. alternative mixed relative absolute
    7·1 answer
  • A _____ is a link on a web page that leads to another web page.
    13·1 answer
  • Do you need to know javascript to learn python?
    8·1 answer
  • A package delivery company or a cell phone company wouldn't go far if it could not deliver products smoothly and reliably. This
    15·1 answer
  • Question #4
    8·1 answer
  • If i keep giving out brainlyest will i get banned again?
    12·2 answers
  • Which of the following operating systems would allow a user to add functionality and sell or give away their versions?
    8·1 answer
  • This rlly isnt a question but give me some movies to watch or netflix movies/shows to watch
    12·2 answers
  • What symbol should you look for to determine who owns the intellectual property of a website? the logo the web address the domai
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!