loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1

loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1

Hi, I want to know how the code to print the pyramid below works. It uses nested for loops.

Pyramid: 1 1234 12 123 123 12 1234 1

View Answers

May 14, 2012 at 1:10 PM

Here is the code that will display some pattern of numbers in the form pyramid.

class Pattern 
{
    public static void main(String[] args){

        for(int i=1;i<=4;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j);
        }
         System.out.println();
        }
         System.out.println();
        for(int i=4;i>=1;i--){
        for(int j=1;j<i+1;j++){
            System.out.print(j);
        }
          System.out.println();
        }
    }
}









Related Tutorials/Questions & Answers:
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1  Hi, I want to know how the code to print the pyramid below works. It uses nested for loops. Pyramid: 1 1234 12 123 123 12 1234 1
print numbers
print numbers  1234 123 12 1234   1234 123 12 1234
Advertisements
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
print this image in java code using only loop{for, if, loop}
print this image in java code using only loop{for, if, loop}  ... is a code that displays the following pattern...;j<9;j++) { s[i][j]='*'; } } for(i=0;i<4;i++) { for(j=1;j<4
WAP in java to print the series 1*2*3
WAP in java to print the series 1*2*3  WAP in java to print the series 123
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for otj-parent-oss version 123
-oss version 123 dependency by just including the code discussed here...-oss version 123. You can add these depency in your project to get com.opentable:otj-parent-oss:123 Java library in your project.. Maven, Gradle, SBT, Ivy
Write a program to print using for loop
Write a program to print using for loop  Write a program to print using for loop * * * *  
java program 12
java program 12  Write a java program to verify whether the given number is palindrome or not by taking from input Buffer reader(console).  ...=""; for(int i=str.length-1;i>=0;i--){ reversedSt+=str[i
python print on same line in loop
data on the same line? What is the best way to print on same line in a loop...python print on same line in loop  Hi, I have a unique requirement in Python where I have to print data in the same line. When I am using
Chapter 12. Exceptions
Chapter 12. ExceptionsPrev Part I. Exam Objectives Next    Chapter 12. ExceptionsIdentify correct and incorrect statements or examples about exception handling
write a program to use for loop print **********========== in c language
write a program to use for loop print **********========== in c language  write a program to use for loop print **========== in c language
Maven Dependency seleniumite >> 0.0.3+12
You should include the dependency code given in this page to add Maven Dependency of com.timeinc >> seleniumite version0.0.3+12 in your project
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
java Question
in four separate program. Pattern1 1 12 123 1234 12345 123456 Pattern2 123456 12345 1234 123 12 1 Pattern3 1 21 321 4321 54321 654321 Pattern4 123456 12345 1234 123 12 1
Code for Pattern
Code for Pattern  1 1 12 12 123 123 1234512345 Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
java code and logic - Java Beginners
java code and logic  how to write the program in java for 123454321 1234 4321 123 321 12 21 1 1 thanks  Hi Friend, Try the following code: class Program { public static void main(String
java
java  hello, i need a java program to print the nos in this manner a) 1 12 123 1234
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts... the following code: import java.util.*; class WashingMachine { Scanner input
javaprograms
javaprograms  compute the following series s=1+12+123+1234+............+123....n terms
print from a-z, A-Z with exact order using for loop
print from a-z, A-Z with exact order using for loop  how to print from a-z, A-Z with exact order using for loop? Thanks for all concern
Maven dependency for com.cedarsoft - open version 12 is released. Learn to use open version 12 in Maven based Java projects
: implementation group: 'com.cedarsoft', name: 'open', version: '12' Above code...Maven dependency for  com.cedarsoft  - Version 12 of open released...; com.cedarsoft - open library is 12. Developer can use this version ( com.cedarsoft
12 Seater Tempo Traveller on rent in Delhi to Rishikesh
12 Seater Tempo Traveller on rent in Delhi to Rishikesh - Luxury Tempo... for river rafting and see the beauty of Rishikesh, Hire our 12 Seater Tempo... are offering 9, 12 and 16 Seater Tempo Traveller from Delhi, Noida and NCR regions
Finding a Factorial using while loop
= 12, factorial = 1, temp = value; while (temp > 0...Finding a Factorial using while loop      In this example we are going to find out the factorial of 12 by using
java code using while loop
java code using while loop  
java programming:generating series
series: 12345 1234 123 12 1 1 12 123 1234 12345 12345   Here is a code that displays the following pattern: 12345 1234 123 12 1 1 12 123 1234...) { for(int i=5;i>=1;i--){ for(int j=1;j<i+1;j
java programming:generating series
java programming:generating series  12345 1234 123 12 1 1 12 123 1234 12345   Here is a code that displays the following pattern: 12345 1234 123 12 1 1 12 123 1234 12345 class Pattern { public
Maven dependency for com.adeptj - adeptj-parent version 12 is released. Learn to use adeptj-parent version 12 in Maven based Java projects
Maven dependency for  com.adeptj  - Version 12 of adeptj-parent... of  com.adeptj - adeptj-parent library is 12. Developer can use this version ( com.adeptj - adeptj-parent version 12 ) in their Java project
Maven dependency for com.timeinc - seleniumite version 0.0.3+12 is released. Learn to use seleniumite version 0.0.3+12 in Maven based Java projects
: 'com.timeinc', name: 'seleniumite', version: '0.0.3+12' Above code will enable...Maven dependency for  com.timeinc  - Version 0.0.3+12 of seleniumite... version of  com.timeinc - seleniumite library is 0.0.3+12. Developer can use
Maven dependency for org.openjfx - javafx-media version 12 is released. Learn to use javafx-media version 12 in Maven based Java projects
Maven dependency for  org.openjfx  - Version 12 of javafx-media... of  org.openjfx - javafx-media library is 12. Developer can use this version ( org.openjfx - javafx-media version 12 ) in their Java project
Finding a Factorial using while loop
are going to find out the factorial of 12 by using the while loop. In while loop...; <% int value = 12, factorial = 1, temp = value...Finding a Factorial using while loop   
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
Maven dependency for org.openjfx - javafx-media version 17-ea+12 is released. Learn to use javafx-media version 17-ea+12 in Maven based Java projects
: '17-ea+12' Above code will enable the Gradle to down org.openjfx - javafx...Maven dependency for  org.openjfx  - Version 17-ea+12 of javafx... version of  org.openjfx - javafx-media library is 17-ea+12. Developer can use
Maven dependency for org.openjfx - javafx-fxml version 17-ea+12 is released. Learn to use javafx-fxml version 17-ea+12 in Maven based Java projects
Maven dependency for  org.openjfx  - Version 17-ea+12 of javafx-fxml... version of  org.openjfx - javafx-fxml library is 17-ea+12. Developer can use this version ( org.openjfx - javafx-fxml version 17-ea+12 ) in their Java project
Maven dependency for org.openjfx - javafx-fxml version 18-ea+12 is released. Learn to use javafx-fxml version 18-ea+12 in Maven based Java projects
: 'org.openjfx', name: 'javafx-fxml', version: '18-ea+12' Above code will enable...Maven dependency for  org.openjfx  - Version 18-ea+12 of javafx-fxml... version of  org.openjfx - javafx-fxml library is 18-ea+12. Developer can use
Maven dependency for org.openjfx - javafx-media version 18-ea+12 is released. Learn to use javafx-media version 18-ea+12 in Maven based Java projects
+12</version> </dependency> Above code is the maven dependency code...: 'org.openjfx', name: 'javafx-media', version: '18-ea+12' Above code...Maven dependency for  org.openjfx  - Version 18-ea+12 of javafx
Which ~12 weeks data science course would you recommend?
Which ~12 weeks data science course would you recommend?  Hi, I am... for the tutorials to learn: Which ~12 weeks data science course would you recommend? Try... "Which ~12 weeks data science course would you recommend?". Also tell
for loop
for loop  what is for loop   Loops are used for iteration which means to execute a part of code repeatedly. Repetition of a part of code can be done for a number of times or infinitely. If repetition of code is done
NSLog print NSString example code
) print;  @endADS_TO_REPLACE_3 The implementation class code is as follows..." ADS_TO_REPLACE_4 @implementation printString -(void) print {ADS
FOR Loop In JSP
FOR Loop In JSP In this section we will read about how to use the for loop... are used e.g. while loop, do while loop, for loop. In programming these loops are differentiated by their syntax. Loop is the execution of statements

Ads