Ejemplo 1: programa Java para encontrar el perímetro de un rectángulo
import java.util.Scanner;
public class PerimeterOfRectangleDemo
{
public static void main(String []args)
{
float length, width, perimeter;
Scanner sc = new Scanner(System.in);
System.out.print("Please enter length of rectangle: ");
length = sc.nextFloat();
System.out.print("Please enter width of rectangle: ");
width = sc.nextFloat();
perimeter = 2 * (length + width);
System.out.println("Perimeter of rectangle: " + perimeter);
sc.close();
}
}
Ejemplo 2: programa java para encontrar el perímetro de un rectángulo
Scanner sc = new Scanner(System.in);
System.out.println("Enter Width of the rectangle: ");
double width = sc.nextDouble();
System.out.println("Enter Height of the rectangle: ");
double height = sc.nextDouble();
sc.close();
// Logic for finding the perimeter of the rectangle
double perimeter = 2 * (width + height);
System.out.println("Perimeter of Rectangle: " + perimeter);
Ejemplo 3: programa java de perímetro de rectángulo
import java.util.Scanner;
public class RectanglePerimeter {
public static void main(String[] args) {
new RectanglePerimeter().getValues();
}
//get user input from console
public void getValues() {
Scanner sc=new Scanner(System.in);
double length= sc.nextDouble();
double breadth=sc.nextDouble();
RectanglePerimeter obj=new RectanglePerimeter();
double result= obj.perimeterCalculator(length,breadth);
System.out.println(result);
}
//write logic to find perimeter of rectangle here
public double perimeterCalculator(double length, double breadth) {
double perimeter=(2*length)+(2*breadth);
return perimeter;
}
}
Ejemplo 4: programa java de perímetro de rectángulo
import java.util.Scanner;
public class RectanglePerimeter {
public static void main(String[] args) {
new RectanglePerimeter().getValues();
}
//get user input from console
public void getValues() {
Scanner sc=new Scanner(System.in);
double length= sc.nextDouble();
double breadth=sc.nextDouble();
RectanglePerimeter obj=new RectanglePerimeter();
double result= obj.perimeterCalculator(length,breadth);
System.out.println(result);
}
//write logic to find perimeter of rectangle here
public double perimeterCalculator(double length, double breadth) {
double perimeter=(2*length)+(2*breadth);
return perimeter;
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)