Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

In Java, ( Display pyramid upside down ) Write a program that prompts the user to enter an integer from 1 to 1 5 and

In Java, (Display pyramid upside down) Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid. My code isn't working and was wondering if someone could fix it:
package chapter5ex3;
import java.util.Scanner;
public class Chapter5Ex3{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a number between 1-15: ");
int numberOfLines = input.nextInt();
int i;
int j;
int k;
int x;
boolean b = true;
for (int rows =1; rows <= numberOfLines; rows++){
for (i = x; i >0; i--){
for (j = i; j >0; j--){
for (k =0; k <((x - i)) && b; k++){
System.out.print("");
}
if (x >9 && j >8 && b){
for (k =0; k <(x - j); k++){
System.out.print("");
}
}
if (x >9 && j <9 && b){
for (k =0; k < x -9; k++){
System.out.print("");
}
}
System.out.print(j +"");
b = false;
}
for (j =2; j <(i +1); j++){
System.out.print(j +"");
}
System.out.println();
b = true;
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions