Java code that calculates the area and perimeter of a rectangle

Status
Not open for further replies.

Matthewza

Posting Freak
Apr 20, 2012
777
77
Hi,

I am trying to write a program in Java that calculates the area and perimeter of a rectangle, I have searched all over the internet and I can't seem to find anything.
 

LeChris

github.com/habbo-hotel
Sep 30, 2013
2,744
1,326
I don't start Java Programming until next year so:

and

or both at once
 

Matthewza

Posting Freak
Apr 20, 2012
777
77
I don't start Java Programming until next year so:

and

or both at once

I'm using NetBeans IDE 6.9.1 to write this if that helps.
 
Last edited:

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Use the forumla?
Area - length * width
Perimter - 2 * length + 2 * width

You want to use a input so
Something like this: I did this quick so
Code:
import java.util.Scanner;

Scanner input = new Scanner(System.in);
System.out.println("Please input Length");
int length = input.nextInt();
System.out.println("Please input Width");
int width = input.nextInt();

System.out.println("Your Area Is: " + getArea(length,width);

public int getArea(int x, int y){
int total = x * y;
return total;
}

DO not just copy this code, understand it and elaborate it a little more
 

Matthewza

Posting Freak
Apr 20, 2012
777
77
Use the forumla?
Area - length * width
Perimter - 2 * length + 2 * width

You want to use a input so
Something like this: I did this quick so
Code:
import java.util.Scanner;

Scanner input = new Scanner(System.in);
System.out.println("Please input Length");
int length = input.nextInt();
System.out.println("Please input Width");
int width = input.nextInt();

System.out.println("Your Area Is: " + getArea(length,width);

public int getArea(int x, int y){
int total = x * y;
return total;
}

DO not just copy this code, understand it and elaborate it a little more

Thanks for the help, I understand it now! :D
 
Status
Not open for further replies.

Users who are viewing this thread

Top