Number Pyramid

Number Pyramid

Hi Everyone, Can someone help me write the code for the following number pyramid:

print("
                                              1
                                        2     0     2
                                  3     0     0     0     3
                            4     0     0     0     0     0     4

... ");

There is 5 spaces in between each number. So far I have this:

print("import java.util.Scanner;

class Pyramid {

public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.print("Please enter a number: "); int x =input.nextInt();

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

    for (int j = 1; j <= x - i; j++)
        System.out.print("      ");

    for (int k = i; k >= 1; k--)
        System.out.print((k >= 10) ?+ k : "     " + k);


    System.out.println();
}

} } ");

and this prints out:

print("
                                              1
                                        2     1     2
                                  3     2     1     2     3
                            4     3     2     1     2     3     4

");

View Answers

January 5, 2013 at 3:06 PM

import java.util.Scanner; class Pyramid {

public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.print("Please enter a number: "); int x =input.nextInt();

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

    for (int j = 1; j <= x - i; j++)
        System.out.print("      ");

    for (int k = i; k >= 1; k--)
        System.out.print((k >= 10) ?+ k : "     " + k);


    System.out.println();
}

} }









Related Tutorials/Questions & Answers:
number pyramid
number pyramid   how to get the code for the following...;class Pyramid{ public static void main(String args[]){ for(int i=1;i<=7...; class Pyramid{ public static void main(String args[]){ for(int i
Number Pyramid
Number Pyramid  Hi Everyone, Can someone help me write the code for the following number pyramid: print... 0 0 0 0 4 ... "); There is 5 spaces in between each number
Advertisements
pyramid
pyramid  hi frnds i need java code for pyramid. the pyramid look like this A BAB CBABC BAB
pyramid
pyramid  hi i need java code for pyramid. the pyramid look like this. A BAB CBABC BAB
pyramid
pyramid  how to get the output like this A BB CCC DDDD   Hi Friend, Try the following code: class Pyramid { public static void main(String[] args) { for(char ch1='A';ch1<='D';ch1
pyramid
pyramid  How to get the code for the following pattern * * * * * * * * * *   class Pyramid{ public static void main(String args[]){ for(int i=1;i<=4;i
pyramid
pyramid  How to get the code for the following pattern * * * * * * * * * *   class Pyramid{ public static void main(String args[]){ for(int i=1;i<=4;i
pyramid
pyramid  how to print 1 22 333 4444 55555   class Pyramid { public static void main(String[] args) { for(int i=1;i<=5;i++){ for(int j=1;j<=i;j++){ System.out.print(i
Pyramid
pyramid
pyramid
pyramid
pyramid
ModuleNotFoundError: No module named 'pyramid'
ModuleNotFoundError: No module named 'pyramid'  Hi, My Python... 'pyramid' How to remove the ModuleNotFoundError: No module named 'pyramid... to install padas library. You can install pyramid python with following command
nmber printed in pyramid format
nmber printed in pyramid format  how to print this format using java 1 23 345 4567 56789
buzz number
buzz number  buzz number
Application for print pyramid of numbers
Application for print pyramid of numbers  What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
Java Pyramid of Numbers
Java Pyramid of Numbers  Hi, I want to know how the code to print the pyramid below works. It uses nested for loops. Pyramid: 1 2 1 2
ModuleNotFoundError: No module named 'opbeat_pyramid'
ModuleNotFoundError: No module named 'opbeat_pyramid'  Hi, My... named 'opbeat_pyramid' How to remove the ModuleNotFoundError: No module named 'opbeat_pyramid' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_addons'
ModuleNotFoundError: No module named 'pyramid_addons'  Hi, My... named 'pyramid_addons' How to remove the ModuleNotFoundError: No module named 'pyramid_addons' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_caching'
ModuleNotFoundError: No module named 'pyramid_caching'  Hi, My... named 'pyramid_caching' How to remove the ModuleNotFoundError: No module named 'pyramid_caching' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_cli'
ModuleNotFoundError: No module named 'pyramid_cli'  Hi, My Python... 'pyramid_cli' How to remove the ModuleNotFoundError: No module named 'pyramid_cli' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'pyramid_contextauth'
ModuleNotFoundError: No module named 'pyramid_contextauth'  Hi, My... named 'pyramid_contextauth' How to remove the ModuleNotFoundError: No module named 'pyramid_contextauth' error? Thanks   Hi
ModuleNotFoundError: No module named 'pyramid_addons'
ModuleNotFoundError: No module named 'pyramid_addons'  Hi, My... named 'pyramid_addons' How to remove the ModuleNotFoundError: No module named 'pyramid_addons' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_amdjs'
ModuleNotFoundError: No module named 'pyramid_amdjs'  Hi, My... 'pyramid_amdjs' How to remove the ModuleNotFoundError: No module named 'pyramid_amdjs' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_angularstarter'
ModuleNotFoundError: No module named 'pyramid_angularstarter'  Hi...: No module named 'pyramid_angularstarter' How to remove the ModuleNotFoundError: No module named 'pyramid_angularstarter' error? Thanks   Hi
ModuleNotFoundError: No module named 'pyramid_appengine'
ModuleNotFoundError: No module named 'pyramid_appengine'  Hi, My... named 'pyramid_appengine' How to remove the ModuleNotFoundError: No module named 'pyramid_appengine' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid_asbool'
ModuleNotFoundError: No module named 'pyramid_asbool'  Hi, My... named 'pyramid_asbool' How to remove the ModuleNotFoundError: No module named 'pyramid_asbool' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_assetviews'
ModuleNotFoundError: No module named 'pyramid_assetviews'  Hi, My... named 'pyramid_assetviews' How to remove the ModuleNotFoundError: No module named 'pyramid_assetviews' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid_authsanity'
ModuleNotFoundError: No module named 'pyramid_authsanity'  Hi, My... named 'pyramid_authsanity' How to remove the ModuleNotFoundError: No module named 'pyramid_authsanity' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid_autodoc'
ModuleNotFoundError: No module named 'pyramid_autodoc'  Hi, My... named 'pyramid_autodoc' How to remove the ModuleNotFoundError: No module named 'pyramid_autodoc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid-avro'
ModuleNotFoundError: No module named 'pyramid-avro'  Hi, My Python... 'pyramid-avro' How to remove the ModuleNotFoundError: No module named 'pyramid-avro' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_basemodel'
ModuleNotFoundError: No module named 'pyramid_basemodel'  Hi, My... named 'pyramid_basemodel' How to remove the ModuleNotFoundError: No module named 'pyramid_basemodel' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid-bootstrap'
ModuleNotFoundError: No module named 'pyramid-bootstrap'  Hi, My... named 'pyramid-bootstrap' How to remove the ModuleNotFoundError: No module named 'pyramid-bootstrap' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid-bugsnag'
ModuleNotFoundError: No module named 'pyramid-bugsnag'  Hi, My... named 'pyramid-bugsnag' How to remove the ModuleNotFoundError: No module named 'pyramid-bugsnag' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid-captcha'
ModuleNotFoundError: No module named 'pyramid-captcha'  Hi, My... named 'pyramid-captcha' How to remove the ModuleNotFoundError: No module named 'pyramid-captcha' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_chameleon'
ModuleNotFoundError: No module named 'pyramid_chameleon'  Hi, My... named 'pyramid_chameleon' How to remove the ModuleNotFoundError: No module named 'pyramid_chameleon' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Pyramid-Classy'
ModuleNotFoundError: No module named 'Pyramid-Classy'  Hi, My... named 'Pyramid-Classy' How to remove the ModuleNotFoundError: No module named 'Pyramid-Classy' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_closure'
ModuleNotFoundError: No module named 'pyramid_closure'  Hi, My... named 'pyramid_closure' How to remove the ModuleNotFoundError: No module named 'pyramid_closure' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid_controllers'
ModuleNotFoundError: No module named 'pyramid_controllers'  Hi, My... named 'pyramid_controllers' How to remove the ModuleNotFoundError: No module named 'pyramid_controllers' error? Thanks   Hi
ModuleNotFoundError: No module named 'pyramid_crud'
ModuleNotFoundError: No module named 'pyramid_crud'  Hi, My Python... 'pyramid_crud' How to remove the ModuleNotFoundError: No module named 'pyramid_crud' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pyramid-cubicweb'
ModuleNotFoundError: No module named 'pyramid-cubicweb'  Hi, My... named 'pyramid-cubicweb' How to remove the ModuleNotFoundError: No module named 'pyramid-cubicweb' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pyramid_debugauth'
ModuleNotFoundError: No module named 'pyramid_debugauth'  Hi, My... named 'pyramid_debugauth' How to remove the ModuleNotFoundError: No module named 'pyramid_debugauth' error? Thanks   Hi, In your

Ads