import java.util.Scanner;
public class Main
{
public static void main(String args[]) throws Exception
{
System.out.println("Number of value to the graph: ");
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n];
int b[]=new int[100];//stores number of occurances of each number
int sum=0;//to calculate frequency
System.out.print("Enter the integer values seperated by space: ");
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();//taking input
b[a[i]]++;
}
int max=0;
System.out.print("Bar graph for ");//printing first line
for(int i=0;i<100;i++)
{
sum=sum+b[i];
if(b[i]>0)
System.out.print(i+" ");
if(max<b[i])
max=b[i];
}
System.out.println();
int x=max;
/*logic for printing # is that max number should have # from first line
where as remaining should have from the line of (max-their value)*/
for(int i=0;i<x;i++)
{
System.out.print(" ");
for(int j=1;j<100;j++)
{
if(b[j]>=max)
System.out.print("# # # # # # ");
else
System.out.print(" ");
}
max--;
System.out.println();
}
for(int i=0;i<100;i++)
if(b[i]>0)
System.out.print("-------------");
System.out.println();
for(int i=0;i<100;i++)
if(b[i]>0)
System.out.print(" "+i);
System.out.println();
for(int i=0;i<100;i++)
if(b[i]>0)
{
double k=(double)b[i]*100/sum;
String s = String.format("%.2f",k);
System.out.print(" "+s);
}
}
}

Need help coding with Java. Explanation in code would be greatly appreciated. Thanks Bar graph 2.0...