import javautilScanner import javatextvalue public class Rec
import java.util.Scanner;
import java.text.value;
public class Rectangle
{
public static void main(String[]args){
System.out.println(\"Find the area of a rectangle\");
System.out.println(\"Find the perimeter of a rectangle\");
System.out.println(\"Enter a number of choice\");
}
public static void main(String[]args){
int choice = //the user choice
double value :0 // the value returned from the method
double length; // the length of rectangle
double width;// the width of rectangle
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter length: \");
double length = scan.nextDouble(); //the length of rectangle
System.out.println(\"Enter width :\");
double width = scan.nextDouble(); //the width of rectangle
double area = length*width; //calculating area
double perimeter = 2*(length+width); //calculating perimeter
System.out.println(\"Area of rectangle is:\" + value);
System.out.println(\"Perimeter of rectangle is:\"+value);
}
}
Please fix this Java program to get output and update it
Solution
Java program to get the output of the rectangle\'s area & perimeter :-
import java.util.Scanner;
public class Rectangle
{
public static void main(String[] args)
{
//Scanner object is one of the connection ehich acts as an interface between Console and Java Application.
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter length: \");
//when we press enter after entering the value, the value is dropped into the scan object.
double length = scan.nextDouble();
// Here scan.nextDouble(); reads the value of the length of the rectangle from scan object.
System.out.println(\"Enter width :\");
//when we press enter after entering the value, the value is dropped into the scan object.
double width = scan.nextDouble();
//Here scan.nextDouble(); reads the value of the width of the rectangle from scan object.
double area = length*width; //calculating area
double perimeter = 2*(length+width); //calculating perimeter
System.out.println(\"Area of rectangle is:\" + area);
System.out.println(\"Perimeter of rectangle is:\"+perimeter);
}
}
Compilation :-
Javac Rectangle.java
Execution :-
Java Rectangle
Output :-
Enter length :
5
Enter width :
5
Area of rectangle is :25.0
Perimeter of rectangle is :20.0
![import java.util.Scanner; import java.text.value; public class Rectangle { public static void main(String[]args){ System.out.println(\ import java.util.Scanner; import java.text.value; public class Rectangle { public static void main(String[]args){ System.out.println(\](/WebImages/45/import-javautilscanner-import-javatextvalue-public-class-rec-1142886-1761613408-0.webp)
![import java.util.Scanner; import java.text.value; public class Rectangle { public static void main(String[]args){ System.out.println(\ import java.util.Scanner; import java.text.value; public class Rectangle { public static void main(String[]args){ System.out.println(\](/WebImages/45/import-javautilscanner-import-javatextvalue-public-class-rec-1142886-1761613408-1.webp)