Practice: Branching

Take out a piece of paper. We’ll be programming on paper.

For the following programming questions, I’d like you to follow the programming algorithm.

1) Read and understand the problem

2) Create the comment stating the problem.

3) Insert the Java boilerplate.

/** Program that ...
 * @author Cam Moore
 */
public class ProgramName {
  /** Does something.
   * @param args the command line arguments.
   */
  public static void main(String[] args) {
    
  }
}

4) Write the steps in pseudo code.

5) Refine the pseudo code.

Problem 1

Write a program that counts from 10 to 30 by three and outputs the number if it is a multiple of four.

Problem 2

Write a program to play Jan Ken Po or Rock Paper Scissors. The computer should choose a random value then ask the user to choose. Then print out who wins.

Problem 3

Write a program that counts from 1 to 100, if the number is a multiple of 3 it should output “fizz”, if the number is a multiple of 5 it should output “buzz”.

Show me your code before you leave

Practice Expressions

int x = 30 + (20 / 5 * 2 - 2);

int y = 30 + 20 / 5 % 2 - 2;

int z = ((30 + 20) / 5) % (2 + 1);