01- Introduction to Java - Exercise 3
Task 1 - if statement
Create a new project called
Conditionals
.Write your code within the
main
method.Ask the user for two numbers and print the bigger one.
Ask the user for another number and print out if it’s odd or event.
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
Comment out the previous code.
Ask the user for a number between 1 and 12.
Based on the number, print if the corresponding month is in Spring, Summer, Autumn or Winter.
Make sure you let the user know if their number choice was invalid.
Task 3 - Calculator
Create a new project called
Calculator
.Within the body of the main method ask the user for two numbers.
Ask the user for an operator.
Considering the user’s chosen operator, perform the correct mathematical operation on the supplied numbers.
Make sure the user knows if they input an invalid operator.
Print out the result.