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
GIVING BRAINLIEST
irakobra [83]

Answer:

A: Radio waves.

Explanation:

Computers use short-wave radio in order to communicate with devices in it's immediate vicinity.

8 0
2 years ago
In the __________ Standard, chemical manufacturers, importers, and distributors are required to provide hazard information by wa
Bas_tet [7]
The correct answer is C
5 0
4 years ago
What do you call a commercial transaction beyween a buisness and buisness thatis transactedd online?
VMariaS [17]

Answer:

c.B2b digital transaction

Explanation:

yan lang po sana makatulong

6 0
3 years ago
Personal Web Page Generator Write a program that asks the user for his or her name, then asks the user to enter a sentence that
Fudgin [204]

Answer:

see explaination

Explanation:

The following code is in python 3.5 and above:

# Create a main method

def main():

# Accept name from the user

name = input("Enter your name: ")

# Accept describe yourself from the user.

describe = input("Describe yourself: ")

# Create a file object

f = open('person.html','w')

# Creat a string to store the html script.

message = """<html>

<head>

</head>

<body>

<center>

<h1>"""+name+"""</h1>

</center>

<hr/>"""+describe+"""<hr/>

</body>

</html>"""

f.write(message)

f.close()

main()

7 0
3 years ago
The following memo does not follow the correct format. What should be changed? To: Stacy, Allen, and Emma Date: August 12, 2012
miss Akunina [59]
<span>The From: line should appear under the To: line.

</span>
4 0
3 years ago
Read 2 more answers
Other questions:
  • Consider a method defined with the header:
    13·1 answer
  • How does Hadoop work? It breaks up Big Data into multiple parts so each part can be processed and analyzed at the same time on o
    5·1 answer
  • Plagiarism occurs when writers
    14·2 answers
  • Which of the following TCP/IP settings should be configured to specify DNS suffixes to use other than resolving names through a
    9·1 answer
  • Which of these statements makes the most sense? a folder is contained within a file. a file is contained within a folder. a driv
    9·2 answers
  • Write a program that has an array of at least 50 string objects that hold people’s names and phone numbers. The program then rea
    12·1 answer
  • How old was the mummy where they found a wooden prosthetic toe on him?
    6·1 answer
  • Hey guys, I don’t have a problem for you but If anyone knows do you still pass your grade level if you failed 1 class in the las
    11·2 answers
  • 4. In paragraph 7, what is the meaning of the phrase "not
    13·1 answer
  • Do you have any sprites for Friday Night Funkin?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!