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

Ads

 
 

Share on Google+Share on Google+

Sara Roz
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
1 Answer(s)      5 years and 5 months ago
Posted in : Java Beginners

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

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

Ads









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
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
Chapter 12. Exceptions
Chapter 12. ExceptionsPrev Part I. Exam Objectives Next    Chapter 12. ExceptionsIdentify correct and incorrect statements or examples about exception handling
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 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
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
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; while (temp > 0...Finding a Factorial using while loop   
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
Finding a Factorial using while loop
Finding a Factorial using while loop      In this example we are going to find out the factorial of 12 by using the while loop. In while loop the loop will run until the condition we have given
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 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
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
java
java  hello, i need a java program to print the nos in this manner a) 1 12 123 1234
javaprograms
javaprograms  compute the following series s=1+12+123+1234+............+123....n terms
Write a program to print using for loop
Write a program to print using for loop  Write a program to print using for loop * * * *  
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
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
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
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