COSC1046 - Chapter 3
COSC1046 - Chapter 3
Chapter 3
We’ll start this lab with the if statement. The syntax looks like:
We can also nest if statements to check for multiple conditions or use the OR or AND operators:
We can also nest the else and else if after our if statement:
The switch statement works like an if statement, but has multiple cases:
Name: Vishw Patel Student I’d(229689040) COSC1046 Lab 1
It is important that break; is included after each case, or else the cases beneath the first executed one
will also execute. What does the default case do?
Write a program that displays the larger of two numbers using a ternary operator
import java.util.Scanner;
For the following program, use if statements to display the number or roots for the equation, and
calculate the roots using the Math.pow() method that is listed at the bottom of the question.