Hello,
somehow my program passes directly to else statement after
System.out.println("Would you like to draw another triangle? (Yes/No): ");
something is wrong with if statement at the end...please help
import java.util.*;
public class Triangle
{
public static void main (String [] args)
{
System.out.println("Welcome to the Triangle Program");
int size;
String rightAnswer = "Yes";
System.out.println("How big of a triangle would you like: ");
Scanner input = new Scanner(System.in);
size = input.nextInt();
if
(size <= 0)
{
System.out.println("Please input a positive integer number for the size of the triangle.");
System.out.println("How big of a triangle would you like: ");
size = input.nextInt();
}
System.out.println("Here is your right-angle triangle of size " + size);
for (int i=0; i<size; i++)
{
for (int f=0; f<i; f++)
{
System.out.print("*");
}
System.out.println("*");
}
System.out.println("Would you like to draw another triangle? (Yes/No): ");
String answer = input.nextLine();
if
(rightAnswer.equalsIgnoreCase(answer))
{
System.out.println("How big of a triangle would you like: ");
size = input.nextInt();
if
(size <= 0)
{
System.out.println("Please input a positive integer number for the size of the triangle.");
System.out.println("How big of a triangle would you like: ");
size = input.nextInt();
}
System.out.println("Here is your right-angle triangle of size " + size);
for (int i=0; i<size; i++)
{
for (int f=0; f<i; f++)
{
System.out.print("*");
}
System.out.println("*");
}
}
else
{
System.out.println("Thank you for using the Triangle Program");
System.exit(0);
}
}
}