Perimeter & Area of Square by Java.
Hello Friends ,
How are you all, hope you are fine. If you are also looking for some Java code from which we can get the area and parameter of a square.So here is the code, by the way you can do it with method recursion also, but I have this object oriented program. Well, both the methods are good..
- The Following Code is Here :-
class square{
int side;
public void area(){
System.out.println("\nThe Area of the square is ~> "+ side* side+" m^2");
}
public void perimeter(){
System.out.println("\nThe Peremiter of the square is ~> "+ 4 * side+" Units");
}
}
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("ENTER THE SIDE OF THE SQUARE :- ");
square number = new square();
number.side = sc.nextInt();
number.area();
number.perimeter(); // CREDITS :- MANDEEP YADAV ..
}
Comments