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
aalyn [17]
2 years ago
6

Construct sequence using a specified number of integers within a range. The sequence must be strictly increasing at first and th

en strictly decreasing. The goal is to maximize the sequence array elements starting from the beginning. For example, [4, 5, 4, 3, 2] beats [3,4,5,4,3] because its first element is larger, and [4, 5, 6, 5, 4] beats [4,5,4,3,2] because its third element is larger. Given the length of the sequence and the range of integers, return the winning sequence. If it is not possible to construct such a sequence, return -1. Write an algorithm that returns a winning sequence and -1 if the sequence is not possible. Input The input to the function/method consists of three arguments: num : an integer representing the size of sequence to create lower End : an integer representing the lower end of integer range upperEnd : an integer representing the upper end of integer range.
Computers and Technology
1 answer:
natulia [17]2 years ago
7 0

Answer:

Explanation:

The following code is written in Java. It first creates a function that takes in the three parameters to create the sequence, if the sequence is valid it returns the created sequence, otherwise it prints -1 and returns an empty array. The second function called compareSequences takes in to sequences as parameters and compares them, printing out the winner. A test case has been provided in the main method and the output can be seen in the image below.

import java.util.Arrays;

class Brainly {

   public static void main(String[] args) {

       int[] seq1 = createSequence(5, 4, 2);

       int[] seq2 = createSequence(5, 3, 3);

       System.out.println("Winner: " + Arrays.toString(compareSequences(seq1, seq2)));

   }

   public static int[] createSequence(int num, int upperEnd, int lowerEnd) {

       int[] myArray = new int[num];

       int middle = (int) Math.floor(num/2.0);

       myArray[0] = upperEnd;

       myArray[num-1] = lowerEnd;

       int currentValue = upperEnd;

       for (int i = 1; i < num-1; i++) {

           if (i <= middle) {

               myArray[i] = currentValue + 1;

               currentValue += 1;

           } else {

               myArray[i] = currentValue - 1;

               currentValue += 1;

           }

       }

       System.out.println(Arrays.toString(myArray));

       if (myArray[num-2] < lowerEnd) {

           System.out.println("-1");

           int[] empty = {};

           return empty;

       } else {

           return myArray;

       }

   }

   public static int[] compareSequences(int[] seq1, int[] seq2) {

       int lowestLength;

       if (seq1.length > seq2.length) {

           lowestLength = seq2.length;

       } else {

           lowestLength = seq1.length;

       }

       for (int i = 0; i < lowestLength; i++) {

           if (seq1[i] > seq2[i]) {

               return seq1;

           } else if (seq1[i] < seq2[i]) {

               return seq2;

           }

       }

       if (seq1.length > seq2.length) {

           return seq1;

       } else {

           return seq2;

       }

   }

}

You might be interested in
A 1024-bit message is sent that contains 992 data bits and 32 CRC bits. CRC is computed using the IEEE 802 standardized, 32-degr
Studentka2010 [4]

Answer:

a) Yes

b) Yes

c) Yes

d) No

e) Yes

f) No

Explanation:

a) All single-bit errors  are caught by Cyclic Redundancy Check (CRC) and it produces 100 % of error detection.

b) All double-bit errors for any reasonably long message  are caught by Cyclic Redundancy Check (CRC) during the transmission of 1024 bit. It also produces 100 % of error detection.

c) 5 isolated bit errors  are not caught by Cyclic Redundancy Check (CRC) during the transmission of 1024 bit since CRC may not be able to catch all even numbers of isolated bit errors so it is not even.

It produces nearly 100 % of error detection.

d) All even numbers of isolated bit errors may not be caught by Cyclic Redundancy Check (CRC) during the transmission of 1024 bit. It also produces 100 % of error detection.

e) All burst errors with burst lengths less than or equal to 32 are caught by Cyclic Redundancy Check (CRC) during the transmission of 1024 bit. It also produces 100 % of error detection.

f) A burst error with burst length greater than 32 may not be caught by Cyclic Redundancy Check (CRC) during the transmission of 1024 bit.

Cyclic Redundancy Check (CRC) does not detect the length of error burst which is greater than or equal to r bits.

4 0
3 years ago
Today you turned on your computer after being on vacation for a week. You see spinning white dots on a black screen. You decide
Andre45 [30]

Answer:

<em>Use Safe Mode to boot</em>

Explanation:

Safe mode uses a <em>limited number of files and drivers to begin Windows in a simple form. If an issue does not arise in safe mode, this means that the problem is not caused by default settings and simple system drivers.</em>

Windows in safe mode helps users to track down the cause of a problem and therefore can enable users to solve problems on the computer.

The steps include:

  1. Reboot your computer.
  2. Click the F8 button before the logo appears on Windows 7 and above.
  3. Using the arrow keys to navigate and select which operating system you would like to boot into Safe Mode if you have more than one operating system installed on the same computer.
  4. Use the arrow keys to select Safe Mode and press Enter.

4 0
3 years ago
Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respect
Irina18 [472]

Answer:

import java.util.Scanner;

public class num2 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter Name");

       String name = in.next();

       System.out.println("Enter Age");

       int age = in.nextInt();

       System.out.println("The age of "+name +" is "+age);

   }

}

Explanation:

Java programming language is used to write the code.

The scanner class is used to prompt and receive values for name and age which are stored in the appropriate variables.

The key idea here is using string concatenation in the output statement in order to print the desired output

3 0
3 years ago
Which option best describes top-down design?
MrRissso [65]
A.Breaking fine à large tas kongo anallergique partis
5 0
1 year ago
2. Write a program to calculate CGPA of a student. The program should be able to get input from the user of the grade for each c
Irina18 [472]
The easy way to do it is to let an array accept all the inputs and add all the inputs together and divide the sum by how many the input was. 

Example : five + five + five + five + three + two = 25
Now divide twenty five : twenty five / six = 4.1

Letter A is the closest answer.
7 0
3 years ago
Other questions:
  • Electrical pressure is also called
    5·2 answers
  • Which is a safe Internet behavior?
    5·1 answer
  • Which data type stores images and audio visual clips?
    9·2 answers
  • A ____ may be composed of a few individual objects or several complex groups of objects.
    9·1 answer
  • Which of the following is an accurate statement? When the LOWER function is used in a SELECT clause, it will automatically store
    6·1 answer
  • All of the following are aspects of the search process except?
    6·2 answers
  • What is the forging of the return address on an email so that the email message appears to come from someone other than the actu
    11·1 answer
  • E-mail has made it very easy to send a message to more than one person at any time of day from just about anywhere. If you wante
    7·1 answer
  • Please help!!! I am very confused about this question!
    10·1 answer
  • A __________is a software program that appears to be a physical computer and executes programs as if it were a physical computer
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!