Go to Top

Sunday 11 December 2011

Utilities 24 : Percentage grapher

This program will represent any number as a percentage of another number in a graphical way. Just compile and see.

Java Program :

import java.io.*;
class per_graph
{
 static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 static int v1,v2,p;
    static void input()throws IOException
    {
        System.out.print("Enter the value : ");
        v1=Integer.parseInt(br.readLine());
        System.out.print("\n"+v1+" is out of : ");
        v2=Integer.parseInt(br.readLine());
        cal();
    }
    static void cal()
    {
        p=(v1*100)/v2;
        display();
    }
    static void display()
    {
        int i;
        System.out.print("\f|");
        for(i=1;i<=100;i++)
        System.out.print("-");
        System.out.print("|\n|");
        for(i=1;i<=p;i++)
        System.out.print("=");
        for(i=1;i<=(100-p);i++)
        System.out.print(" ");
        System.out.print("|\n|");
        for(i=1;i<=100;i++)
        System.out.print("-");
        System.out.print("|\n\n\t\t\t\t\t"+p+" % out of 100 %");
    }
}
    

No comments:

Post a Comment

ShareThis