How to calculate Rectangle Area using Java

How to calculate Rectangle Area using Java

The previous post, javawe were able to calculate circle are using Java .Today we are going to calculate rectangle area.

Calculating rectangle are code

[
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CalculateRectangleArea {


    public static void main(String args[])
    {

        int area=CalculateRectangleArea();
        System.out.println("Rectangle Area is"+area);

    }


    public static int CalculateRectangleArea()
    {

        int w=0;
        int l=0;
        try        {
            BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Please enter Rectangle Width");
            w=Integer.parseInt(reader.readLine());

            System.out.println("Please enter Rectangle length");
            l=Integer.parseInt(reader.readLine());


        }

        catch(NumberFormatException ne)
        {
            System.out.println("Inavalid number entered"+ne);
            System.exit(0);

        }
        catch(IOException ioe)
        {
            System.out.println("Inavalid number entered"+ioe);
            System.exit(0);

        }

        int area=l*w;
        return area;

    }
} 
]

Code Explanation:

There are some key points to note with above program.

I have used  [public static int CalculateRectangleArea()] to calculate and return rectangle area.int is the return type.if a method is declared void,it means the method will not return anything.
The method is declared static because it has to be used in a static context.

Exceptions errors occurs incase user enters invalid numbers.Its wise to catch exceptions in your program to ensure runs well.In advanced java programs,notifications are made using [JOptionPane.showMessageDialog()]

See also 

How to calculate Cirlce Area in Java




COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: How to calculate Rectangle Area using Java
How to calculate Rectangle Area using Java
How to calculate Rectangle Area using Java
Java Codes
http://www.download-all.net/2017/02/how-to-calculate-rectangle-area-using.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/02/how-to-calculate-rectangle-area-using.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy