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]
3 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]3 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
You want to multiply 50 in cell D3 by 8.90 in cell E3. Which formula should you use?
Effectus [21]

Answer:

The formula is =D3*E3

Explanation:

To multiply the items in 2 cells, the formula like every other in excel begins with = .

to multiply 50 in cell D3 by 8.90 in cell E3 the formula to be used is

=D3*E3

This will multiply the numbers in both cell and show as 445.

7 0
4 years ago
By itself, the human eye cannot see anything in three dimensions. What does the passage say enables us to see the world in 3-D?
algol13

Answer:

he miracle of our depth perception comes from our brain's ability to put together two 2D images in such a way as to extrapolate depth. This is called stereoscopic vision.

Explanation:

4 0
3 years ago
Read 2 more answers
One part of a development team has completed an algorithm. Why is it important to share it with others on the team? Choose all t
Nadusha1986 [10]

Answer: B,C,D

Explanation:

5 0
3 years ago
_____ (without parity) means spreading the data among multiple (at least two) drives. Group of answer choices Parity
Llana [10]

Answer:

"Disk Striping" would be the right choice.

Explanation:

  • Disk stripping has become a methodology where certain numerous small external drives consist of a single massive disk. This same classification turns huge information into single blocks but instead disperses them over numerous different storage media.
  • Disk stripping retail outlets instead of every data unit through a single place and doesn't provide disk failure safeguards.
3 0
3 years ago
What should you do to help prepare yourself for the delivery of your presentation? you can chose more then one
Lubov Fominskaja [6]
1 makes sense for somewhere you haven't been before. 2 could be interesting, but it's a bit superfluous if not required. 3 is the most important and essential. Some teachers don't want presenters to look at the board/read their slides word for word when they present, so it might be a good idea to have note cards instead.

Hope this helps!
4 0
3 years ago
Other questions:
  • Question 4 of 10
    5·1 answer
  • What qualifies as a dependent (a) 25 year old son/daughter making$5k per year living at home, (b) 21 year old friend going to sc
    10·1 answer
  • Your browsing the Internet and realize your browser is not responding which of the following will allow you to immediately exit
    14·2 answers
  • How do Hlookup and Vlookup differ?
    5·2 answers
  • As in algebra, you can use brackets to override the order of operations Excel follows to perform formula calculations. True or f
    13·1 answer
  • Extend to also calculate and output the number of 1 gallon cans needed to paint the wal. Hint: Use a math function to round up t
    12·1 answer
  • How to write conclusion of hard disk​
    11·1 answer
  • MR. Tom asked her students could they plant a flower and bring it to class. Sarah brought his flower and said it was a rose. Jam
    6·1 answer
  • Write a paragraph discussing privacy issues on the internet<br> and their impact on human lives.
    9·1 answer
  • write ms-dos command to list all the files and folders of EIGHT sub directory of C: drive in ascending order according to file n
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!