Number Pyramid

Ads
 

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();
}

} }

Ads









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
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
prime number
prime number  To check a number entered by user is prime
Armstrong number
Armstrong number  I want java program for Armstrong number
prime number
prime number  write a java program for prime number
prime number
prime number  to check wethere given number is prime or not?  ... { static boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...++; } } System.out.println("The number of vowels in the given sentence
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
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
VoIP Number
VoIP Number VoIP Numbers With a VoIPtalk Incoming number, callers can reach you by calling a UK number no matter where you are, Simply plug... connection and anyone can reach you by dialling your individual number. The VoIPtalk
nmber printed in pyramid format
nmber printed in pyramid format  how to print this format using java 1 23 345 4567 56789

Ads