Last active
September 15, 2016 21:14
-
-
Save dhust/d50c3a1d59a78a3b0d06 to your computer and use it in GitHub Desktop.
Using the AND Compound Logical Operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// Variables | |
Scanner in = new Scanner(System.in); | |
int shapeLength; | |
String shape; | |
// Get length and shape from the user | |
System.out.print("Enter the length of the shape: "); | |
shapeLength = in.nextInt(); | |
System.out.print("Enter the name of the shape: "); | |
shape = in.next(); | |
// If BOTH "shapeLength < 100" AND | |
// "shape.equalsIgnoreCase("square")" are TRUE, | |
// then the body of that code will run | |
if ( shapeLength < 100 && shape.equalsIgnoreCase("square")) { | |
System.out.println("That square is small."); | |
} | |
else if (shapeLength >= 100 && shape.equalsIgnoreCase("square")) { | |
System.out.println("That square is large."); | |
} | |
else { | |
System.out.println("I only like squares."); | |
} | |
// Close the scanner | |
in.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment