Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: bridge course Pseudo Code Assignment: Looping Instructions: We looked at looping in class. Java has a while loop and a for loop.These are

Java Programming: bridge course

Pseudo Code

Assignment: Looping

Instructions: We looked at looping in class. Java has a while loop and a for loop.These are both pre-test loops.The for loop is a definite loop and the while loop is an indefinite loop.(Java also has a post-test indefinite loop:do..while.

Here is the general format for the while loop in pseudo code:

while BOOLEAN EXPRESSION

statements here that will be repeated

end while

As discussed, Boolean expressions are expressions that evaluate to true or false.These are formed by relational operators (<. >,< =,>=, !=) and the logical operators AND && and OR ||.

For loops:

For loops are definite pre-test loops.Use these when you want to repeat something some fixed number of times.

Pseudo code for the for loop:

for count = 1 to 5 step 1

these statements repeat

end for

Pseudo code for the do .. while loop

do

these statements repeat

while BOOLEAN EXPRESSION

Which to use?

Use a while loop when you don't know exactly how many times the loop will repeat (indefinite loop)

Use a for loop when you know exactly how many times the loop will repeat (definite loop)

Both these loops are pre-test loops which means that if the first test fails (is false) then the statements in the loop body are never executed.

The do while loop is also indefinite but is post test so that loop runs the code block at least once before the first test.

For each of the following tasks, provide the complete pseudo code including all elements that we have been using (i.e. class, end class, main return, output prompt).Be sure to declare your variables and use symbolic constants where appropriate.Determine if each task requires a definite or indefinite loop and use the correct one.

Question: Code a number guessing game.The user picks a number between 1 and 10 and the computer 'guesses' the value. Each time, the player indicates if the guess is larger or smaller by entering a plus or a minus sign.If the computer guesses the value correctly then the user enters a exclamation point !. Assume in this case that the player/user it truthful.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions