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.

use a while loop and check if the string matches the wtwo options.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.