Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that you are trying to write a program that produces the following output using loops. The program below is an attempt at a solution,

Suppose that you are trying to write a program that produces the following output using loops. The program below is an attempt at a solution, but it contains at least four major errors. Identify and fix them all. Your solution must have a class constant. A constant must be declared as 'public static final' outside of any methods in your class.

1 3 5 7 9 11 13 15 17 19 21

1 3 5 7 9 11

public class BadNews { public static int MAX_ODD = 21;

public static void writeOdds() { // print each odd number int count=0; for ( count = 1; count <= (MAX_ODD - 2); count++) { System.out.print(count + " "); count = count + 1; }

// print the last odd number System.out.print(count); System.out.println(); }

public static void main(String[] args) { // write all odds up to 21 writeOdds();

// now, write all odds up to 11 MAX_ODD = 11; writeOdds(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago