Conditional Statements are a core part of programming and everyday life. When writing a program will have to tell the computer to execute some statements based on present conditions. Example below:
Picture, you’re lost in the woods and you come to a fork in the road. You have a decision to make. Do you go left or right? If you go left then you have 2 more miles to go before finding shelter (Mountain Lions live that way), Else if you go right you will have 8 more miles before finding shelter (Bunnies live that way).
pubic class Woods {
public String navigateTheWoods(String direction){
// if the value inside the if-statement is true go left
if(direction.equals("Left")){
System.out.println("You have 2 miles left. Beware of the
Mountain Lions!!!");
}// else if the value inside the else-if is true go right
else if(direction.equals("Right")){
System.out.println("Oh no 8 more miles left. Bunnies are so
cute");
}
}
}