by Dinesh Thakur Category: Classes

 

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles