/
01- Introduction to Java - Exercise 3

01- Introduction to Java - Exercise 3

Task 1 - if statement

  1. Create a new project called Conditionals.

  2. Write your code within the main method.

  3. Ask the user for two numbers and print the bigger one.

  4. Ask the user for another number and print out if it’s odd or event.

  5. Ask the user for a traffic light colour and print the corresponding instruction: i.e. green means go, red means stop.

Task 2 - switch statement

  1. Comment out the previous code.

  2. Ask the user for a number between 1 and 12.

  3. Based on the number, print if the corresponding month is in Spring, Summer, Autumn or Winter.

  4. Make sure you let the user know if their number choice was invalid.

Task 3 - Calculator

  1. Create a new project called Calculator.

  2. Within the body of the main method ask the user for two numbers.

  3. Ask the user for an operator.

  4. Considering the user’s chosen operator, perform the correct mathematical operation on the supplied numbers.

  5. Make sure the user knows if they input an invalid operator.

  6. Print out the result.

Related content