1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
melomori [17]
4 years ago
15

Write a program that asks the user to enter the size of a triangle (an integer from 1 to 50). Display the triangle by writing li

nes of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user. On the next line write one fewer asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only one asterisk in displayed. (Hint: Use nested loops; the outside loop controls the number of lines to write, and the inside loop controls the number of asterisks to display on a line. Complete the program by solving the upper triangle followed by the lower triangle.)
Computers and Technology
1 answer:
dsp734 years ago
4 0

Answer:

import java.util.Scanner;

public class num4 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int size;

       do{

           System.out.println("Enter size of triangle");

           size = in.nextInt();

       }while(size<=1 || size>=50);

       for(int i = 1; i <= size; ++i) {

           for(int j = 1; j <= i; ++j) {

               System.out.print("* ");

           }

           System.out.println();

       }

       System.out.println();

       //Second triangle bottom up

       for(int i = size; i >= 1; --i) {

           for(int j = 1; j <= i-1; ++j) {

               System.out.print("* ");

           }

           System.out.println();

       }

   }

}

Explanation:

  • Use Scanner class to receive user value for size
  • Use a do......while loop to ensure user entered a valid range (1-50)
  • Use nested loops to print the first triangle from i = 1
  • Print also the second triangle from i = size downwards
You might be interested in
A(n) ____ is a program that you use to create simple text files.
tatiyna

A <u>Text editor </u>is a program that you use to create simple text files.

<h3>What is the text editor?</h3>

A text editor is known to be a kind of a computer program that is known to give room for a user to be able to enter, alter , store, and also be able to print text (such as characters as well as numbers, each is known to be encoded by the computer as well as its input and output devices, set up to have meaning to a given users or to other kinds of programs).

Therefore, based on the above, one can say that A <u>Text editor </u>is a program that you use to create simple text files.

Learn more about Text editor from

brainly.com/question/4004088
#SPJ1

A(n) ____ is a program that you use to create simple text files. a. text editor b. IDE c. GUI d. GDE.

3 0
1 year ago
Edhesive 6.3 question 1
hjlf
Is there supposed to be a picture?..
3 0
3 years ago
True or false?
Fed [463]

Answer:

True

Explanation:

Storing gathered multimedia files for an instructional video in a single folder is good practice because this method makes it easier for the user to access and manage the files. The files can also be easily transferred if there is need to since everything is stored in one central area.

Keeping a record of the source information is also important as this helps the instructor to control files and have quick access to any of the files.

4 0
4 years ago
In a distributed database system, the data placement alternative with the highest reliability and availability is Group of answe
Ivahew [28]

Answer:

fully replicated

Explanation:

4 0
3 years ago
Define text processor​
jenyasd209 [6]

Answer:

The manuplating of text, especially the transformation of text from one format to another.

6 0
3 years ago
Other questions:
  • What special identity group specifically includes any user account (except the Guest) logged into a computer or domain with a va
    14·1 answer
  • Where is a 3D modeler most likely to work?
    6·1 answer
  • The purpose of a database is to help people stop using spreadsheets.
    10·1 answer
  • Which command should you use if you want your workbook with a different file name?
    15·1 answer
  • James would like to send a document he has saved on the hard drive to coworkers in Ireland, Brazil, and India. These coworkers h
    6·2 answers
  • A misplacement of punctuation or spacing in a command during programming that causes the program to stop running is most
    9·2 answers
  • What G-Suite Apps integrate with Forms
    14·2 answers
  • Indicate whether the following statements are true or false:
    14·2 answers
  • Why is it necessary to have usernames and passwords if one is working on a network?​
    12·1 answer
  • What does an arrow after a command indicate
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!