0

For the below program:

 import java.util.*;
   public class triangleLoop {
      public static void main (String[] args) {
         int height, row, col, spa;
         String leftOrRight;
            char hyp;
         Scanner kbd = new Scanner(System.in);
         System.out.println("Enter the desired height of the triangle: ");
         height = kbd.nextInt();
            kbd.nextLine();
         System.out.println("What side do you want the hypoteneuse on? Left or Right:");
         leftOrRight = kbd.nextLine().toLowerCase();
                if ((leftOrRight.compareTo("left")) || (leftOrRight.compareTo("right"))) {
                    System.out.println("Only enter Left or Right!");
                    leftOrRight = kbd.nextLine().toLowerCase();
                }

                hyp = leftOrRight.charAt(0);
}}

I want leftOrRight to be only "left" or "right" if its not i want the user to have to keep entering strings until it meets those perameters, but my boolean expressions i think are wrong.

3
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

In english the logic is:

while (input is not equal to "right" AND input is not equal to "left")
    tell user to enter right or left
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.