by Dinesh Thakur Category: Classes

 

import java.io.*;

class rect
{
            int l,b;
            void setval(int x,int y)
            {
                        l=x;
                        b=y;
            }
            int area()
            {
                        return (l*b);
            }
};
class RectangleUsingClasses
{
            public static void main (String args[]) throws IOException
            {
                        BufferedReader g=new BufferedReader(new InputStreamReader (System.in));
                        String h;
                        int p,q;
                        rect k=new rect();
                        System.out.println("Enter Length and Breadth : ");
                        h=g.readLine();
                        p=Integer.parseInt(h);
                        h=g.readLine();
                        q=Integer.parseInt(h);
                        k.setval(p,q);
                        System.out.println("Area of Rectangle is :"+k.area());
            }
};

Java Example to Calculate Area of Rectangle Using Classes, Values Not Given

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.



Search Content







Popular Article