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
An office uses an application to assign work to its staff members. The application uses a binary sequence to represent each of 1
fenix001 [56]

Answer: I believe the answer is: A, 5.

Explanation:

6 0
3 years ago
Assume that printStars is a function that takes one argument and returns no value. It prints a line of N stars (followed by a ne
trasher [3.6K]

Answer:

printStars(35);

Explanation:

public class Question {

   public static void main(String args[]) {

     printStars(35);

   }

   public static void printStars(int numberOfStars){

       for(int i = 1; i <= numberOfStars; i++){

           System.out.print("*");

       }

       System.out.print("\n");

   }

}

7 0
3 years ago
Explain the role of computers in accounting
Inessa05 [86]

Answer:

A computer helps accountants store and access financial records, make changes and alleviate the need to keep paper files. If paper work is needed, computer files can easily be accessed and printed along with any changes the accountant makes at any given time.

8 0
2 years ago
Modify an array's elements Write a for loop that iterates from 1 to numberSamples to double any element's value in dataSamples t
ValentinkaMS [17]

Answer:

See explaination for program code

Explanation:

%save as AdjustMinValue.m

%Matlab function that takes three arguments

%called number of samples count, user samples

%and min vlaue and then returns a data samples

%that contains values which are double of usersamples

%that less than min vlaue

%

function dataSamples=AdjustMinValue(numberSamples, userSamples, minValue)

dataSamples=userSamples;

%for loop

for i=1:numberSamples

%checking if dataSamples value at index,i

%is less than minValue

if dataSamples(i)<minValue

%set double of dataSamples value

dataSamples(i)= 2*dataSamples(i);

end

end

end

Sample output:

Note:

File name and calling method name must be same

--> AdjustMinValue(4, [2,12,9,20],10)

ans =

4 12 18 20

3 0
2 years ago
In python 3.17 LAB: Convert to dollars
krok68 [10]

To convert the inputs to dollars and cents, we make use of a combination of multiplication and addition.

The program written in Python where comments are used to explain each line is as follows:

<em />

<em>#This gets input for the number of quarters</em>

quarters = int(input("Quarters: "))

<em>#This gets input for the number of dimes</em>

dimes = int(input("Dimes: "))

<em>#This gets input for the number of nickels</em>

nickels= int(input("Nickels: "))

<em>#This gets input for the number of pennies</em>

pennies= int(input("Pennies: "))

<em>#This converts the amount to dollars and cents</em>

dollars = quarters * 0.25 + dimes * 0.10 + nickels * 0.05 + pennies * 0.01

<em>#This prints the amount to 2 decimal places</em>

print("Amount ${:.2f}".format(dollars))

Read more about Python programs at:

brainly.com/question/22841107

7 0
2 years ago
Other questions:
  • The OSHA Workplace Poster 3165 is optional for workplaces.<br> A) True<br> B) False
    13·2 answers
  • Round-robin schedulers normally maintain a list of all runnable processes, with each process occurring exactly once in the list.
    14·1 answer
  • Free points! your welcome
    9·2 answers
  • What does limited access to a document mean?
    14·2 answers
  • If we can lock a file, we can solve the race condition problem by locking a file during the check-and-use window, because no oth
    14·1 answer
  • How do you freeze the total cell so that it doesn't change when copied?
    6·1 answer
  • 9
    10·1 answer
  • Explain in your own words how remote-access Trojans (RATs) work. How can these be used by attackers? How would a network adminis
    10·1 answer
  • Extended essay on globalization not less than 200​
    6·1 answer
  • What makes you normally visit the site-graphics, layout, or content? Why?​
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!