Printing numbers in pyramid format

Printing numbers in pyramid format

Q) Can you please tel me the code to print the numbers in the following format:
1
2 3
4 5 6
7 8 9 10
View Answers

June 30, 2010 at 2:54 PM

Hi Friend,

Try the following code:

public class Pyramid{
public static void main (String[] args) throws Exception{
int k = 1;
for(int i=1; i<= 4 ;i++){
for(int j=1; j <= i ; j++){
System.out.print(k+" ");
k = k + 1;
}
System.out.println("");
}
}
}

Thanks









Related Tutorials/Questions & Answers:
Printing numbers in pyramid format - Java Beginners
Printing numbers in pyramid format  Q) Can you please tel me the code to print the numbers in the following format: 1... the following code: public class Pyramid{ public static void main (String
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
Advertisements
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8
nmber printed in pyramid format
nmber printed in pyramid format  how to print this format using java 1 23 345 4567 56789
Printing numbers up to N into a file
Printing numbers up to N into a file  I'd like to print the first N integers, that is, "1, 2, 3, 4, ..., N-1, N", say N equals 1000, or 10000 or whatever. I'd also like to have the result stored as a file instead of having
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
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
printing java series
printing java series  * *** ***** ******** ***** *** *   Post the format properly
printing in swing
printing in swing  How can i print payslip in swing
applet printing
applets gridwise and in each applet i am drawing some graph so while printing whole... but while printing it is not getting printed on paper and rest everything it is printing
printing in java
printing in java  hello i want to print a jInternalframe containing some lebels,but my printer sent me a paper with the following written on it: please what is the problem
Printing stars
Printing stars  I am a beginer and i have one assignment which couldnt give me any idea how to do it..The Question is "Get a string "001222014654" and print o/p as 0 - * 1- ** 2- * 4- ** 5-* 6-* I dont know how to split
Java program for printing document
Java program for printing document  can u send me the java program for printing the office document? email: [email protected]
Number Format Example
Number Format Example       This Example shows you how to format numbers according to the locale... numbers. NumberFormat class also provides methods for defining which locales have
ModuleNotFoundError: No module named 'Printing'
ModuleNotFoundError: No module named 'Printing'  Hi, My Python... 'Printing' How to remove the ModuleNotFoundError: No module named 'Printing... to install padas library. You can install Printing python with following
printing records from jsp - JSP-Servlet
printing records from jsp  Hi Plz tell me how to printing out pages from jsps with page numbers Thank you  Hi friend, For paging in Jsp visit to : http://www.roseindia.net/jsp/paging.shtml http
Printing server information
Printing server information  Hello, I am learning PHP language. I trying to fetch the server Information Print. How could i will printing the server... connected to your PC? This it best example for the Printing server Information
print numbers in traingle shape
print numbers in traingle shape  1 22 333 4444 i want output like this please help me   class Pyramid { public static void main(String[] args) { for(int i=1;i<=4;i++){ for(int j=1;j<
printing example - Java Beginners
printing example  Is it possible to print java controls using print method? My problem is to print a student mark list using java? The mark list should like that of university mark list
number pyramid
;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
Struts 2 Format Examples
Struts 2 Format Examples       In this section you will learn how to format Date and numbers in Struts 2 Framework. Our Struts 2 Format Examples are very easy to grasp and you will learn these concepts
automorphic numbers
automorphic numbers  how to find automorphic number in java   Hi Friend, Pleas visit the following link:ADS_TO_REPLACE_1 Automorphic numbers Thanks
Java Printing - Java Beginners
Java Printing  Can anybody plz help in giving the code for printing the contents of JPanel.. It contains JLabels and JTextFields only.. Plz.. Its urgetn.. Printing means sending the document to the Printer..  Hi Friend
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
how printing landscape?
how printing landscape?  I have code which print some data from data base with "drawString()" and it works correct when I chose "Portrait" from "Print Dialog", but it does not work if chose "Landscape". Is any way to print
printing hollow square
printing hollow square  Write an application (PrintingSquares.java) that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work
numbers
Prime Numbers
Prime Numbers  Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents
printing press training course
printing press training course  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: printing... that I can learn the topic "printing press training course". Also tell
Number Pyramid
for the following number pyramid: print.... So far I have this: print("import java.util.Scanner; class Pyramid { public... Pyramid { public static void main(String[] args) { Scanner input = new Scanner
Printing ArrayList - JSP-Servlet
Printing ArrayList   I have a code in servlet like this ArrayList total = new ArrayList (); session.setAttribute("efg",total); RequestDispatcher rd; rd = request.getRequestDispatcher("/checkout.jsp"); rd.forward
ModuleNotFoundError: No module named 'Printing-For-Noobs'
ModuleNotFoundError: No module named 'Printing-For-Noobs'  Hi, My... named 'Printing-For-Noobs' How to remove the ModuleNotFoundError: No module named 'Printing-For-Noobs' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'colour-printing'
ModuleNotFoundError: No module named 'colour-printing'  Hi, My... named 'colour-printing' How to remove the ModuleNotFoundError: No module named 'colour-printing' error? Thanks   Hi, In your python
printing series in java
printing series in java  1 123 12345 1234567 12345 123 1   Here is a code for the following pattern: 1 123 12345 1234567 12345 123 1 class Pattern{ public static void main(String[] args
Pyramid
pyramid
pyramid
pyramid
pyramid
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator
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
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 ->... this amount in this format:- 1,099.00
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 ->... this amount in this format:- 1,099.00
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name", "Date of birth", "PPS number"}; String [] personal= {value1, value2, value3}; I want this 2 arrays to be printed out in the following manner: head[0] tab
printing the following output using for loop
printing the following output using for loop  1 2 3 3 4 5 4 5 6 7

Ads