Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class CalArea{
- public static float area(float side){
- return side*side;
- }
- public static float area (float length, float breadth){
- return length * breadth;
- }
- }
- class Area{
- private static String getInput(String prompt){
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- System.out.print(prompt);
- System.out.flush();
- try{
- return stdin.readLine();
- }catch(Exception e){
- return "Error: " + e.getMessage();
- }
- }
- static public void main (String[] args){
- CalArea o = new CalArea();
- String input = getInput("Enter side's value: ");
- float side = Float.parseFloat(input);
- System.out.println("The Sqare's area is "+o.area(side)+" units square.");
- input = getInput("Enter length's value: ");
- float length = Float.parseFloat(input);
- input = getInput("Enter breadth's value: ");
- float breadth = Float.parseFloat(input);
- System.out.println("The Rectangle's area is "+o.area(length, breadth)+" units square.");
- }
- }
- // Output:-
- // C:\Java>java Area
- // Enter side's value: 56.43
- // The Sqare's area is 3184.345 units square.
- // Enter length's value: 12.78
- // Enter breadth's value: 80.11
- // The Rectangle's area is 1023.8058 units square.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement