Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

 1 4 1 9 4 1 16 9 4 1 

Run again? Enter y or n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

1 What are the dimensions used in Hofstedes model of culture?

Answered: 1 week ago