Friday, 21 October 2016

Write a java program to display Rhombus

import java.util.*;
class Rhombus
{
  public static void main(String args[])
 {
   Scanner sc=new Scanner(System.in);
  System.out.print("Enter the pattern number");
  int pat=sc.nextInt();
  System.out.print("Enter the pattern character symbol");
  String s=sc.next();
  char c = s.charAt(0);
  for( int i=1;i<=pat;i++)
  {
    for(int j=1;j<=(pat-i);j++)
    System.out.print(" ");
    for(int k=1;k<=i;k++)
    System.out.print(c+" ");
    System.out.println();
  }

   for(int i=pat-1;i>=0;i--)
  {
    for(int j=1;j<=(pat-i);j++)
    System.out.print(" ");
    for(int k=1;k<=i;k++)
    System.out.print(c+" ");
    System.out.println();
  }
 }
}

No comments:

Post a Comment