For Loop

Java Pyramid 3 Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

23 Comments

  • sir can i favor to you please give me a code, i want to request to you to give me a code of this program using bufferedreader by for loops. the program to be like this: TO BE diamond pattern

    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *

    • class Pyramid3{
      public static void main(String st[]){

      int i,j;
      for(i=1;i<=5;i++)
      {
      for(j=0;j<i;j++) {=”” system.out.println(“*”);=”” }=”” system.out.println(“=”” “);=”” }=”” for(i=”4;i”>0;i–)
      {
      for(j=0;j<i;j++) {=”” system.out.println(“*”);=”” }=”” system.out.println(“=”” “);=”” }=”” }=”” }=””>

    • for (int i=1; i<=5; i++){
      for(int x=i; x<=i; x++){
      System.out.print(“*”);
      }
      System.out.printla ();
      }
      for (int r=1; r<=4; r++){
      for(int y=5; y>=r; y–){
      System.out.print(“*”);
      }
      System.out.printla ();
      }

  • sir can i favor to you please give me a code, i want to request to you to give me a code of this program using bufferedreader by for loops. the program to be like this: TO BE diamond pattern

    *
    * *
    * * *
    * * * * * *

    • for(int z = 0 ; z <=4 ; z ++)
      {
      for(int x = 0 ; x <= z ; x ++)
      {
      if(x>2)
      {

      }
      else
      {
      System.out.print(“*”);
      }
      }
      if(z>2)
      {
      System.out.print(“”);
      }
      else
      {
      System.out.println(“”);
      }
      }

    • import java.io.*;
      class prmd2
      {
      public static void main(String args[])
      {
      System.out.println(“dhana pyramid”);
      for(int i=0;i<=5;i++)
      {
      for(int j=0;j<i*2-1;j++) system.out.print(“*”);=”” system.out.println();=”” }=”” }=”” }=””>

    • for(int z = 5 ; z >= 0 ; z–)
      {
      for(int x = 0 ; x <=z ; x++ )
      {
      System.out.print(“*”);
      }
      System.out.println(“”);
      }
      for(int z = 0 ; z <= 5 ; z ++)
      {
      for(int x = 0 ; x <=z ; x++)
      {
      System.out.print(“*”);
      }
      System.out.println(“”);
      }

    • for (int i=5; i>=1; i–){
      for(int x=1; x<=i; x++){
      System.out.print(“*”);
      }
      System.out.printla ();
      }
      for (int r=0; r<=3>; r++){
      for(int y=0; y<=r+1; y++){
      System.out.print(“*”);
      }
      System.out.printla ();
      }

    • import java.io.*;
      class prmd
      {
      public static void main(String args[])
      {
      for(int i=0;i<5;i++)
      {
      for(int j=i;j<5;j++)
      System.out.print(“*”);
      System.out.println();
      }
      for(int i=0;i<5;i++)
      {
      for(int j=0;j<i+1;j++) system.out.print(“*”);=”” system.out.println();=”” }=”” }=”” }=””>

    • public class JavaPyramid4 {

      public static void main(String[] args) {

      for(int i=1; i<= 5 ;i++){

      for(int j=1; j <= i; j++){
      System.out.print(“*”);
      }
      System.out.println(“”);
      }
      for(int i=4;i>=0;i–)
      {
      for(int j=1;j<=i;j++)
      {
      System.out.print(“*”);
      }
      System.out.println(“”);

      }

      }
      }

Sponsors

Facebook Fans