Question

Ask the user to enter a number.
Using the for statement, create the image of a pyramid using asterisks. Use the input to determine the height of the pyramid. For instance, if the user enters 3, the pyramid will be three rows high.

Display the table in this format (for an input of 3):

         *
       ***
    *****

Note that each row has an odd number of asterisks. Also note that the middle asterisk of each row is aligned vertically.
Repeat the program until the user chooses to quit.
Submit your source code as a plain text file with a .java extension.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class Pyramid {

public static void main(String[] args){
// initialize the scanner
Scanner inputScanner = new Scanner(System.in);

// prompt the user for input
System.out.print("Please enter a number or the letter \"q\" to quit:");

// get user input
String userInput = inputScanner.next();

// as long as the user did not select to quit by typing "q" or "Q"
while(!userInput.equalsIgnoreCase("q")){

// convert the user input to an integer
int userNumber = Integer.parseInt(userInput);...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Classes in Java Programming
Homework Solution
$20.00
Java
Programming
Coding
Classes
OOP
Instances
Variables
Constructor
Parameters
Loops
Strings
Integers
Conditions
Statements
Setters
Getters
Error Handling
Odd Numbers Problem in Java
Homework Solution
$10.00
Java
Programming
Computer Science
Mathematics
Integers
Odd Values
Even Values
Output
Input
Range
Loops
Conditions
Statements
Samples
Rock, Paper, Scissors Program
Homework Solution
$60.00
Programming
Java
Computer Science
Rock Paper Scissors
Game
MySQL
Tables
Queries
Results
Rounds
Probability
Loops
Conditions
Winning
Losing
User vs Computer
Databases
Simple & Compound Interest Using Java
Homework Solution
$65.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Simple Interest
Compound Interest
Money
Finance
Annual Rates
Calculations
Functions
Screen Messages
Java Programming: Strings, Odd & Even Numbers, Absolute Values
Homework Solution
$25.00
Java
Programming
Computer Science
Odd Numbers
Even Numbers
Integers
Absolute Values
While Loop
IF-Statements
Data Sets
Input
Output
Sum
Functions
Methods
Strings
Lexicography Order
Get help from a qualified tutor
Live Chats