Get Instant Help From 5000+ Experts For
Get Instant Help From 5000+ Experts For
  

Java Program Example – To calculate the area of a rectangle.

By HWA | Publish On: September 2, 2011 | Posted In:

Java Program Example

The example Java program is about how to calculate the area of a rectangle.

Calculate Rectangle Area using Java Example

This Calculate Rectangle Area using Java Example shows how to calculate area of Rectangle using it’s length and width.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class CalculateRectArea {

public static void main(String[] args) {

int width = 0;

int length = 0;

try

{

//read the length from console

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Please enter length of a rectangle”);

length = Integer.parseInt(br.readLine());

//read the width from console

System.out.println(“Please enter width of a rectangle”);

width = Integer.parseInt(br.readLine());

}

//if invalid value was entered

catch(NumberFormatException ne)

{

System.out.println(“Invalid value” + ne);

System.exit(0);

}

catch(IOException ioe)

{

System.out.println(“IO Error :” + ioe);

System.exit(0);

}

/*

* Area of a rectangle is

* length * width

*/

int area = length * width;

System.out.println(“Area of a rectangle is ” + area);

}

}

/*

Output of Calculate Rectangle Area using Java Example would be

Please enter length of a rectangle

10

Please enter width of a rectangle

15

Area of a rectangle is 150

*/

For more details you can visit our websites at https://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

Book Your Assignment

Drop files here or click to upload.
Or click here to upload

Recent Posts

51 Top Topics for Masters Thesis in Biomedical Engineering

Read More

200+ Exclusive Legal Thesis Topics For 2024

Read More

How To Write Methodology In Thesis?

Read More

Boost Your Thesis Writing: 11 Proven Tips with Statement Examples!

Read More

The Ultimate Guide to Crafting a Killer Thesis Statement

Read More

Get assignment help from subject matter experts!

4.7/5 rating | 10,000+ happy students | Great tutors 24/7