Question
Code wont compile and gives me and error on while(answer.equalsIgnoreCase(y));: import java.util.Scanner; public class TriangleofSquares { public static void main(String[] args) { Scanner input =
Code wont compile and gives me and error on "while(answer.equalsIgnoreCase("y"));":
import java.util.Scanner;
public class TriangleofSquares {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String answer;
do {
System.out.print("Enter Number between 1 and 9 : ");
int n = input.nextInt();
while(n < 0 || n >=9)
{
System.out.print("Please enter a valid value between 1 and 9 :");
n = input.nextInt();
}
System.out.println("Here Is the Result");
for(int i=0;i { for(int j=0;j<=n*2-(i+i);j++) { System.out.print(" "); } for(int l=i+1;l>0;l--) { int r=l*l; System.out.print(r+" "); } System.out.println(" "); System.out.print("Run again? Enter y or n"); answer = input.next(); } } while(answer.equalsIgnoreCase("y")); } } If a user enters "4" then this should be the output Run again? Enter y or n 1 4 1 9 4 1 16 9 4 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started