Negative subarrays

Assignment Help JAVA Programming
Reference no: EM13876428

Java Programming:

Write a program that displays the "Negative subarrays".

Note: Subarrays are contiguous chunks of the main array. For example if the array is {1,2,3,5} then some of the subarrays are {1}, {1,2,3}, {2,3,5}, {1,2,3,5} etc. But {1,2,5} is not an subarray as it is not contiguous. A sub-array is "Negative" if all the integers in that sub-array is negative.

Your code will prompt for length of the array and it will read the N integers. Next, find all negative sub-arrays and display the results. The order of the subarrays is NOT important when you are displaying.

Example Run #1:

Enter array length: 5
Enter array elements: 1 -2 3 -4 5
Negative sub-arrays of the given array are: 
-2 
-4 

Example Run #2:

Enter array length: 6
Enter array elements: 6 -2 -8 -10 -7 5
Negative sub-arrays of the given array are: 
-2 
-8 
-10 
-7
-2 -8 
-8 -10 
-10 -7 
-2 -8 -10
-8 -10 -7
-2 -8 -10 -7

Example Run #3:

Enter array length: 10 
Enter array elements: -2 -5 -1 2 -3 0 1 -7 -4 -6
Negative sub-arrays of the given array are: 

 

-2 

-5 

-1 

-3 

-7 

-4 

-6 

-2 -5 

-5 -1 

-7 -4 

-4 -6 

-2 -5 -1 

-7 -4 -6 

Reference no: EM13876428

Questions Cloud

Implementing a binary tree write a generic implementation : Implementing a Binary Tree Write a generic implementation of a binary tree class using an internal node class TreeBinUMUC and NodeTreeBin
Describe abell three dimensional business definition model : Describe Abell's three-dimensional business-definition model and explain where it can be utilized. Then, consider Reader's Digest Association, publisher of Reader's Digest, the largest circulation magazine in the world in 1992.
What is the firms horizon or continuing value : Hart Enterprises recently paid a dividend, Do, of $3.25. It expects to have non constant growth of 24% for 2 years followed by a constant rate of 8% thereafter. The firm's required return is 12% what is the firm's horizon, or continuing, value?
Consider risky portfolio-cash flow derived : Consider a risky portfolio. The end-of-year cash flow derived from the portfolio will be either $50,000 or $150,000, with equal probabilities of .5. The alternative risk less investment in T-bills pays 5%. If you require a risk premium of 10%, how mu..
Negative subarrays : Write a program that displays the "Negative subarrays".Note: Subarrays are contiguous chunks of the main array. For example if the array is {1,2,3,5} then some of the subarrays are {1}, {1,2,3}, {2,3,5}, {1,2,3,5} etc. But {1,2,5} is not an subarray ..
Prepare a budgeted income statement : Cameron Parts has the following data from year 1 operations, which are to be used for developing year 2 budget estimates:
Sunk costs concept associated with making capital investment : Define the sunk costs concept associated with making capital investment decisions. Discuss why this concept is important for the investor to factor into the decision-making process.
Write a java program that stores these integers : 3. Write a java program that stores these integers 10, 20, 30, 40, 20 in an array named nums. Write the code to count all the occurrences of 20 and then display the count.
Define and discuss the concepts of risk and return : Define and discuss the concepts of risk and return. Also discuss the importance of portfolio diversification and its relationship to risk and return.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a test program that obtains from the user

Write a test program that obtains from the user the items to store in two sets A and B, and displays the union A u B, the inter- section A n B, and the dierence A \ B. The data type of the items is your choice. ( you can only store objects.)

  Own file to test your program

Create your own file to test your program. Your job is to set up the input and output files to have the program read from a file and write to a file. Here is a basic program that will accomplish what is desired

  Write a java program that draws a square abcd

Write a java program that draws a square ABCD. The points A and B are arbitrarily specified by the user by clicking the mouse button. The orientation of the points should be counter-clockwise

  When would a gui (graphical user interface) be a poor choice

Discuss the following questions with your classmates: When would a GUI (graphical user interface) be a poor choice for reading data into a program? Why? Please give specific reasons for your answer.

  Statement that creates and initializes a static variable

Write a statement that creates and initializes a static variable named salesTax to 7.59. Write a statement that creates a constant variable named TAX_RATE. The tax rate is 8.25%

  Prepare a polynomial-time algorithm

Write a polynomial-time algorithm that, given an initial configuration (P_1, P_2, ..., P_k), decides if it is a winning configuration - Prepare a polynomial-time algorithm that decides if it is a winning configuration.

  Use counting sort to sort an array

State the difficulty in attempting to use counting sort to sort an array of n floating-point numbers from the continuous interval [0,1].

  String as its parameter and returns the length

Write a method named longestWord that accepts a String as its parameter and returns the length of the longest word in the string.A word is a sequence of one or more non-space characters (any character other than the space character).

  Provide a regular expression that shows the set of strings

Provide a regular expression that shows the set of strings over {a, b} thatcontain at least one b if its length is at least four.

  Create a recursive factorial program

Assignment 1: Create a recursive factorial program that prompts the user for an integer  N  and writes out a series of equations representing the calculation of  N !. For example, if the input is 4, the output could be:

  How do i use an ejb to handle simple authentication

What is the difference between an Application server and a Portal server? How do I use an EJB to handle simple authentication to an LDAP directory?

  The program randomly generates the quiz question one by

the program randomly generates the quiz question one by one from a set of available questions on general knowledge

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd