Problem

Find the ErrorFix all syntactical and logical errors in the following segments. Assume tha...

Find the Error

Fix all syntactical and logical errors in the following segments. Assume that input (a Scanner) has been previously declared.

a. int count = 0; int number;

int sum = 0; // sum of the positive numbers among the first 15 numbers entered interactively while count<15

{

number = input.nextInt();

if (number > 0)

sum = sum + number;

}


b. for (int i = 10, sum = 0; i > 5; i++) // sum of the squares of 5 numbers entered interactively

{

int number = input.nextInt();

sum = number * number;

}


c. for (int i = 1, sum = 0; i < = 10; i++)

sum += i * i;

System.out.println ('The sum of the first 10 squares is " + sum);


d. // adds numbers entered interactively using —999 as a flag.

while (input.nextInt() != − 999)

sum = sum + input.nextInt();

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5
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