by Dinesh Thakur

 

import java.io.*;

class avg
{
            int a,b,c;
            float d;
            void setdata(int x,int y,int z)
            {
                        a=x;
                        b=y;
                        c=z;
            }
            void average()
            {
                        d=(float)(a+b+c)/3;
                        System.out.println("Average of three variables is "+d);
            }
};
class AverageThreeVariables
{
            public static void main (String args[])
            throws IOException
            {
                        BufferedReader g=new BufferedReader(new InputStreamReader(System.in));
                        String h;
                        int p,q,r;
                        avg k=new avg();
                        System.out.println("Enter Three Numerical Values");
                        h=g.readLine();
                        p=Integer.parseInt(h);
                        h=g.readLine();
                        q=Integer.parseInt(h);
                        h=g.readLine();
                        r=Integer.parseInt(h);
                        k.setdata(p,q,r);
                        k.average();
            }
};

Calculate Average of Three Variables Using Classes in Java Example