Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java absolutely skips a procedure, please help

807603Oct 28 2007 — edited Oct 28 2007
This is my program, when it gets to the exit command y, or no, it totally skips the whole procedure, can you please help. Thank you in advance

here is my code
Line: -----
import java.util.*;

public class amazingdawg{
public static void main(String[] args) {	
final int minheight = 1;
final int maxheight = 20;
int choice,height,tr1,tr2,tr3,tr4;
String y="y";

Scanner in = new Scanner(System.in);

while ((y.equals("y"))||(y.equals("Y"))){

System.out.print("Enter your choice (1-4): ");
choice = in.nextInt();
while(choice < 1 || choice > 4) {
System.out.print("Enter your choice (1-4): ");
choice = in.nextInt();
}

System.out.print("Enter the height: ");
height = in.nextInt();

while(height < minheight || height > maxheight) {
System.out.print("Enter the height: ");
height = in.nextInt();
}

switch(choice) {
case 1 : System.out.println ("Here is the triangle: \n"); 
for (int i = 1; i <= height; i++)
     {   System.out.print("*");
      
      for (int k =2; k <= i; k++)
     {   System.out.print("*"); 
      
      }System.out.println();
      }
       break;
case 2 : System.out.println ("Here is the triangle: \n");

for (int i = 1; i <= height; i++){
	System.out.print("*");
      
    for (int k =(height-1); k >= i; k--){ 
     System.out.print("*"); 
      
      }System.out.println();
}
 break;
case 3 : System.out.println ("Here is the triangle: \n");
for (int i = height; i > 0; i--)
              {
                for (int j = i; j > 0; j--)
                {
                  System.out.print(" ");
                }
                for (int k = height; k >= i; k--)
                {
                  System.out.print ("*");
                }
                System.out.println ();
              }
               break;
case 4 : System.out.println ("Here is the triangle: \n");
   for (int i = 1; i <= height; i++)
        {
          for (int j = height; j > i; j--)
          {
            System.out.print(" ");
          }
          System.out.print("*");
          for (int a = 1; a < i; a++)
          {
            System.out.print("*");
          }
          for (int c = 1; c < i; c++)
          {
            System.out.print("*");
          }
          System.out.println();
        }
         break;
}
System.out.print ("Would you like to exit (Y or N): ");
y=in.nextLine();

if ((y.equals("n")) || (y.equals("N"))){
	System.out.println ("Thank you for using Triangle Generator.  Good Bye!!");
}else{
	System.out.println("WTF ENTER SOMETHING!!");
}

}
}
}
THE END PART IS WHERE IT SKIPS

Edited by: vertozia on Oct 28, 2007 11:50 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 25 2007
Added on Oct 28 2007
2 comments
90 views