Print Diamond Number Pattern Program Type 5

4 comments on “Print Diamond Number Pattern Program Type 5”


  • prashant

    //Easiest way
    public class random
    {
    public static void main(String[] args)
    {
    int i,j,n=8,k=2,c=0;
    for(i=1;i<=n;i++)
    {
    if(i<=n/2)
    {
    c=k;
    for(j=1;j<=i;j++)
    System.out.print(k++);
    }
    else
    {
    k=c;
    for(j=1;j<=n-i+1;j++)
    System.out.print(k++);
    c=c-(n-i);
    }
    System.out.println();
    }
    }
    }


  • harsh

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {

    int i,j,n;
    Scanner in = new Scanner(System.in);
    System.out.println(“Enter the rows: “);
    n= in.nextInt();
    int num=2;
    for(i=1;i<=n;i++)
    {
    for(j=1;j=1;i–)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(temp);
    temp++;
    }

    System.out.println();
    num=num-(i-1);
    temp=num;
    }
    }
    }


    • harsh

      import java.util.*;
      public class Main
      {
      public static void main(String[] args) {

      int i,j,n;
      Scanner in = new Scanner(System.in);
      System.out.println(“Enter the rows: “);
      n= in.nextInt();
      int num=2;
      for(i=1;i<=n;i++)
      {
      for(j=1;j=1;i–)
      {
      for(j=1;j<=i;j++)
      {
      System.out.print(temp);
      temp++;
      }

      System.out.println();
      num=num-(i-1);
      temp=num;
      }
      }
      }


      • Karthik Murahari

        public static void main(String[] args) {
        int sum=2;
        int sum1=8;
        for (int i = 1; i <= 4; i++) {
        for (int j = 1; j = 1; i–) {
        for (int j = 1; j <= i ; j++) {
        System.out.print(sum1+" ");
        sum1++;
        }
        sum1 = (sum1/2)-1 ;
        if(sum1==1){
        sum1=2;
        }
        System.out.println();
        }
        }