Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1

Have Programming Question? Ask it here!
 
 
 


Sara Roz
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
1 Answer(s)      2 years and 4 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


Advertisement
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
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
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   
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
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
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
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
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
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
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 * * * *  
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
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
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
Counting
on pop up menu. 1 12 123 1234 12345 123456 1234567 12345678 123456789   Java Print Pattern 1 12 123 1234 12345 123456 1234567 12345678 123456789... i=1;i<=9;i++){ for(int j=1;j<i+1;j
Java Interview Questions - Page 12
Java Interview Questions - Page 12   ... to transfer data. Question: Does the code in finally block... will not be executed when the System.exit(1) statement is executed earlier
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
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
How can print integer in method
process(int jobid,int remain){ } how to print int jobid ,int remain in for loop jobid in proc[0],remain in proc[1],both show in text file how to print proc[0] & proc[1] in System.out.println() proc[0]:12 1 4 3 proc[1]:13 7 3 1 thankyou
java code using while loop
java code using while loop  
MySQL add month
MySQL add month In this section we will learn how to add 1 month, 2 month and 12 month to a date object in MySQL. The MySQL DATE_ADD function is used... example shows how to add 1 month to a date object: SELECT DATE_ADD('
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
; NSString *string;    } -(void) print;  @end The implementation class code is as follows: // //  printString.m //  DataTypes // #import "printString.h" @implementation printString -(void) print
loop error - Ajax
, as i mention.. after giving my code the out put shows.... 1 2...loop error  Expert:ARIJEET sory....dude....it's not my perfect solution... i give the code...just like...    
loop
to output the following code using a loop the code is as follows with the user inputs in inverted commas,thanks. ENTER CODE(XX to Stop) CODE:"D24" QUANTITY:"2" CODE:"K19" QUANTITY:"1" CODE:"XX"   import java.util.*; class Output
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
patterns printing using for loop in java
patterns printing using for loop in java  how to write the code for the pattern as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
java
java   give me program for this output 12345 1234 123 12 1   public class PatternExample{ public static void main(String[] args){ for(int i=5;i>=1;i--){ for(int j=1;j<i+1;j
java programming:generating series
java programming:generating series  1234554321 1234 4321 123 321 12 21 1 1   Here is a java code that displays the following pattern 1234554321 1234 4321 123 321 12 21 1 1 class Pattern
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo C  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print
for loop
for loop  using only two for loop how can print below numbers 1... 5 4 4 4 4 3 3 3 2 2 1   Here is a number pattern: 1 2 2 3 3... 2 2 1 class Pattern{ public static void main(String[] args
Advertisements
 

 

 

DMCA.com