Blog o’ Will Cook for Food
Not just another Wordpress blog

4.7-4.9

1 a.

i is equal to 1. while i is less than or equal to the variable ‘limit’, add one to i.

if i divided by 2 results in the remainder 0, print the value of i.

b.       Generate a new random number. The computer assigns a number between 1 and 10. Declare variable x to have a value of 0, and declare the variable “yourNumber”

While x is equal to 0, print out the lines

“I’m guessing a number between 1 and 10. Which number is it?”

The user inputs a number which is assigned to the variable “yourNumber”

If the variables’ values are the same, the computer will print

“That’s it!”

if not, the computer will print

“Sorry, try again.”

2.

a.

x = 0

while (x < 10){

System.out.println��(x * x)

System.out.println(x * x * x)

x++

x++

}

b.

x = 20

while (x > 0){

–x

–x

System.out.println(x)

}

4.8

1. opens a scanner on the file “myfile.txt”

4.9

1. a.
b.  number += 2; is not a valid statement

No Responses Yet to “4.7-4.9”

Leave a Reply