Question

The following piece of code is intended to find the count of negative numbers in the array. The code compiles correctly but i

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer:
Logic error1:
line 5 has a logic error.
i should be initialized with 0 not with 1.
FIX:
for (int i = 0;i<=list.length;i++)

Logic error2:
Line 7 has a logic error.
You have to remove semicolon at the end of line 7.
FIX:
if(list[i] < 0)
Add a comment
Know the answer?
Add Answer to:
The following piece of code is intended to find the count of negative numbers in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please!!! I need the answer in full details studying for Exams!!! Question 3 What is wrong...

    Please!!! I need the answer in full details studying for Exams!!! Question 3 What is wrong with this code? Write the corrected code. // INTENT: calculate the average of all the numbers read in. // sample data: 7 9 10 3 8-5 Corrected Incorrect int count; int sum; int num = sc.next(); while (num > 0) { count++; sum = num; System.out.println(sum/count);

  • There are four syntax errors/incorrect statements in the following class definition. List the line numbers of...

    There are four syntax errors/incorrect statements in the following class definition. List the line numbers of the lines that contain errors, and then write the corrected line(s). (4 points) class jetType //Line 1 { //Line 2 public: //Line 3 void setValues(string, int, double); //Line 4 print() const; //Line 5 string getManufacturer() const; //Line 6 double getPrice() const; //Line 7 bool compareSeating(const jetType&); //Line 8 int jetType(); //Line 9 jetType(string); //Line 10 jetType(string, int, double); //Line 11 private; //Line 12 string...

  • Problem: Use the code I have provided to start writing a program that accepts a large...

    Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Write a c++ code into the given code  to find composite numbers from the given random number...

    Write a c++ code into the given code  to find composite numbers from the given random number list. The composite numbers is only counted once if there is a repeated number. I need to use this code and add on a code to find if the numbers generated is a composite function. Please help #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> using namespace std; int main() {    srand(time(NULL)); int size_of_list = 0; // the number of random...

  • Assume the variable LIST is defined as a list of numbers. Write a code segment that...

    Assume the variable LIST is defined as a list of numbers. Write a code segment that utilizes a loop to total up all of the numbers in the list up to, but not including, the first negative number. Store the result in the variable TOTAL. % test cases % LIST = [ 1 4 6 -2 7 9]; TOTAL = 11; % LIST = [ -2 4 5 7 9]; TOTAL = 0; % your code segment here %----------------------- %...

  • QUESTION 8 What (if anything) will be the output of the following code: int count =...

    QUESTION 8 What (if anything) will be the output of the following code: int count = 3; while (count++ <= 6) { System.out.print(++count + " "); } 3 4 5 6 4 5 6 7 3 4 5 6 7 5 7 4 6 The above code contains a syntax error and will not run. 8 points    QUESTION 9 What (if anything) will be the output of the following code: int count = 0; while (count < 5) {...

  • Consider the following code: *How many elements in the array A are * also in the...

    Consider the following code: *How many elements in the array A are * also in the array B? Assume B is sorted. */ 01: int overlap (int* A, int* B, int N) 02:{ 03: int count = 0; 04: for (int i = 0; i < N; ++i) 05: 06: int x A [i 07: 08 int pos lower_bound (B, B+N, x) - B; if (pos N && B [pos] 09: 10: 11: 12: == x ) { +count; 13:...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • 1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat&#...

    1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat"); a. dog b. dogcat c. \\dog\\cat d. \dog\cat e. catdog\\\\             3.   What is returned by the call     getIt(9) ? public static int getIt(int num){ int ans = 0; if( num >=2 ) {      if( num >= 7)         ans += 2;      else         ans += 3; } ans += 4; return ans; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT