import java.util.*;
class Rhombus
{
public static void main(String[] arg)
{
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();
}
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac SortOrder.java
C:\Users\Jaisha\Desktop\Java>java SortOrder
Enter the array size: 5
Enter Array elements:
Element No. 1: 5
Element No. 2: 3
Element No. 3: 62
Element No. 4: 1
Element No. 5: 52
Before Sorting: 5 3 62 1 52
After Sorting in ascending order: 1 3 5 52 62
After Sorting in descending order: 62 52 5 3 1
class Rhombus
{
public static void main(String[] arg)
{
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();
}
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac SortOrder.java
C:\Users\Jaisha\Desktop\Java>java SortOrder
Enter the array size: 5
Enter Array elements:
Element No. 1: 5
Element No. 2: 3
Element No. 3: 62
Element No. 4: 1
Element No. 5: 52
Before Sorting: 5 3 62 1 52
After Sorting in ascending order: 1 3 5 52 62
After Sorting in descending order: 62 52 5 3 1
No comments:
Post a Comment