Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Triangle Pattern Write a program that reads in lines from the input. Each line has a single integer followed by a single character. The

Java

Triangle Pattern

Write a program that reads in lines from the input. Each line has a single integer followed by a single character. The objective is to print a triangle pattern using the input character. The first integer represents the number of rows of the triangle. Input values will contain only integers greater than or equal to 1 and less than or equal to 50.

Input

The format of an input line is noRows char The first is an integer (and can be read using nextInt()). The last one is a single character (like *) and can be read using next() as a String and then using charAt(0) to get at the first character.

Output

For each line of input, a triangular pattern is printed consisting of several rows. If the no of rows is less than or equal to zero or more than 50, the program prints out an error statement as shown in the sample output.

Sample Input

2 *

-1 '

10 =

Sample Output

*

* *

error in input

=

==

===

====

=====

======

=======

========

=========

==========

HINT

1. use in.next().charAt(0) to get the character.

2. dont forget to discard the rest of the input line using in.nextLine() if you are using in.hasNextLine() to check if there is a next line.

3. You will need two loops for this one as well.

The outputs need to be spot on or it will not pass my online submission (CYOJ) Thanks.

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago