Java Program to calculate perimeter and space of sq. in Java
Anyway, right here is full Java Program to calculate space and perimeter of a Sq. in Java:
import java.util.Scanner; /* * Java Program to calculate the Perimeter and Space of a Sq. */ public class Essential { public static void major(String args[]) { // creating scanner to simply accept radius of circle Scanner scanner = new Scanner(System.in); System.out.println("Welcome in Java program to calculate the Perimeter and space of sq."); System.out.println("Please enter size or aspect of sq. :"); int aspect = scanner.nextInt(); int perimeter = perimeter(aspect); int space = space(aspect); System.out.println("perimeter of sq.: " + perimeter); System.out.println("space of sq.: " + space); scanner.shut(); } /** * Java methodology to calculate perimeter of a sq. * * @param aspect * @return perimeter of sq. */ public static int perimeter(int aspect) { return 4 * aspect; } /** * Java methodology to calculate space of a sq. * * @param aspect * @return space of sq. */ public static int space(int aspect) { return aspect * aspect; } } Output Welcome in Java program to calculate the Perimeter and space of sq. Please enter size or aspect of sq. : 2 perimeter of sq.: 8 space of sq.: 4
You possibly can see that when use entered aspect of sq. as two, our program accurately printed that space can be 4 which aspect * aspect and perimeter can be 8 which is 4 occasions of aspect.
That is all about find out how to calculate Space and Perimeter of a given Sq. in Java. If you’re studying coding then it is best to resolve these form of downside to first learn to convert your ideas and information to code. Relaxation can observe
Some extra Java Coding Train for Programmer