Skip to content

Instantly share code, notes, and snippets.

@dhust
Last active September 15, 2016 21:14
Show Gist options
  • Save dhust/d50c3a1d59a78a3b0d06 to your computer and use it in GitHub Desktop.
Save dhust/d50c3a1d59a78a3b0d06 to your computer and use it in GitHub Desktop.
Using the AND Compound Logical Operator
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