15 Juta per Bulan dari Bisnis Wifi Rumahan, Minim Modal!
15 Juta per Bulan dari Bisnis Wifi Rumahan Hai para calon p…
Rekomendasi Pengharum Mobil 2023
15 Juta per Bulan dari Bisnis Wifi Rumahan, Minim Modal!
5 kelebihan samsung Galaxy z Flip4, yang bikin kamu pegen beli
Anyway, here is complete Java Program to calculate area and perimeter of a Square in Java:
import java.util.Scanner;/** Java Program to calculate the Perimeter and Area of a Square*/public class Main {public static void main(String args[]) {// creating scanner to accept radius of circleScanner scanner = new Scanner(System.in);System.out.println("Welcome in Java program to calculate the Perimeter and area of square");System.out.println("Please enter length or side of square :");int side = scanner.nextInt();int perimeter = perimeter(side);int area = area(side);System.out.println("perimeter of square: " + perimeter);System.out.println("area of square: " + area);scanner.close();}/*** Java method to calculate perimeter of a square* * @param side* @return perimeter of square*/public static int perimeter(int side) {return 4 * side;}/*** Java method to calculate area of a square* * @param side* @return area of square*/public static int area(int side) {return side * side;}}OutputWelcome in Java program to calculate the Perimeter and area of squarePlease enter length or side of square :2perimeter of square: 8area of square: 4
You can see that when use entered side of square as two, our program correctly printed that area would be 4 which side * side and perimeter would be 8 which is four times of side.
That’s all about how to calculate Area and Perimeter of a given Square in Java. If you are learning coding then you should solve these kind of problem to first learn how to convert your thoughts and knowledge to code. Rest can follow
Some more Java Coding Exercise for Programmer
\