Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+21 votes

public static void oddStuff() {
int number = 4
for (int count = 1; count <= number; count++) {
System.out.println(number);
number = number / 2;
}
}

output: 4

        2
asked in CSC211_Winter2018 by (1 point)

2 Answers

+11 votes
 
Best answer

I would recommend running this code through the Online Java Visualizer, to see how it runs step-by-step, and what the value of the variables are at each step. However, to run it, you'll need to change it into a full Java class with a main method, like this:

public class OddStuffTest {
  public static void main(String[] args) {
    oddStuff();
  }
  public static void oddStuff() {
    int number = 4;
    for (int count = 1; count <= number; count++) {
      System.out.println(number);
      number = number / 2;
    }
  }
}

If watching it execute step-by-step doesn't help, I believe our dedicated tutor Maegan will still be in the Olin 204 lab tonight from 7-9 PM tonight (despite the blizzard!), and she could certainly help you out!

Hopefully one of your classmates will also post a more detailed answer than this!

answered by (508 points)
selected by
+5

Thank you! I got it!

–1 vote

I agree with this

answered by (1 point)
...