Write a java program that uses nested for-loops to display a sequence of numbers. The program should ask the user to enter an integer n. The number n should be in the range 3 to 1000. If the number is not in the range, then display an invalid message and exit the program. Otherwise, on the first line, the program should display the number n repeated n times. Then on the next line it should display the number n-1 repeated n-1 times, and on the next line it should display the number n -2 repeated n - 2 times, and so on for the next lines and stop when the number reaches zero. Also, display a star (*) before each line and display a hash (#) at the end of each line. SAMPLE INPUT/OUTPUT If n = 2 If n = 3 If n = 6 *3332 *223 Invalid 8999999* 55555# +44444 3334 *224 number 14

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 14E
icon
Related questions
Question
Java program
Write a java program that uses nested for-loops to display a sequence
of numbers. The program should ask the user to enter an integer n.
The number n should be in the range 3 to 1000. If the number is not in
the range, then display an invalid message and exit the program.
Otherwise, on the first line, the program should display the number n
repeated n times. Then on the next line it should display the number
n-1 repeated n-1 times, and on the next line it should display the
number n -2 repeated n - 2 times, and so on for the next lines and
stop when the number reaches zero. Also, display a star (*) before
each line and display a hash (#) at the end of each line.
SAMPLE INPUT/OUTPUT
If n = 3
If n = 2
If n = 6
*6666664
55555#
+44442
333#
*224
*333#
*223
Invalid
number
*1#
*1#
Transcribed Image Text:Write a java program that uses nested for-loops to display a sequence of numbers. The program should ask the user to enter an integer n. The number n should be in the range 3 to 1000. If the number is not in the range, then display an invalid message and exit the program. Otherwise, on the first line, the program should display the number n repeated n times. Then on the next line it should display the number n-1 repeated n-1 times, and on the next line it should display the number n -2 repeated n - 2 times, and so on for the next lines and stop when the number reaches zero. Also, display a star (*) before each line and display a hash (#) at the end of each line. SAMPLE INPUT/OUTPUT If n = 3 If n = 2 If n = 6 *6666664 55555# +44442 333# *224 *333# *223 Invalid number *1# *1#
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr