Skip to content

Commit

Permalink
Bar chart using asterisks
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Feb 5, 2024
1 parent d9f6804 commit 105a9c7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Bar_chart_using_astersiks.jav
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.*;
public class Program
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
//input of number of test cases
int t=scn.nextInt();
int[] arr=new int[t];
//taking input
for(int i=0;i<arr.length;i++)
{
arr[i]=scn.nextInt();
}
//finding maximum value input to make that number of rows
int max=arr[0];
for(int i=1;i<arr.length;i++)
{
if(arr[i]>max)
max=arr[i];
}
for(int floor=max;floor>=1;floor--)
{
for(int i=0;i<arr.length;i++)
{
if(arr[i]>=floor)
{
System.out.print("*\t");
}
else
System.out.print("\t");
}
System.out.println();
}
}
}

0 comments on commit 105a9c7

Please sign in to comment.