Question: When Using this code: import java.util.Scanner; public class Main { public static double perimeterRectangle(double length, double width) { double perimeter; // variable declarartion perimeter=2*(length+width); //
When Using this code: import java.util.Scanner;
public class Main
{
public static double perimeterRectangle(double length, double width)
{
double perimeter; // variable declarartion
perimeter=2*(length+width); // Find perimeter of rectangle
return perimeter; // return perimeter of rectangle
}
public static void main(String [] arg)
{
Scanner keyboard=new Scanner(System.in);
double length, width,perimeter;
System.out.printf("Please enter length of rectangle:");
length=keyboard.nextDouble(); // Accept length
System.out.printf("Please enter length of rectangle:");
width=keyboard.nextDouble(); // Accept width
perimeter=perimeterRectangle(length, width); // calling function
System.out.printf("Perimeter of rectangle is %.2f ", perimeter); // print perimeter of a rectangle
}
}
Or this code :
import java.util.Scanner; public class Methods2 { public static double average(double p1, double p2) { double ave; ave=(p1+p2)/2; return ave; }//end of average /** * this method will return the perimeter of rectangle * @param p1 * @param p2 * @return perimiter of rectangle */ public static double perimeter(double p1, double p2){ return 2*(p1+p2); }//end of perimeter public static void main(String [] arg) { System.out.printf(" Hello from main"); Scanner keyboard=new Scanner(System.in); double num1, num2; System.out.printf(" Please enter number one:"); num1=keyboard.nextDouble(); System.out.printf(" Please enter number two:"); num2=keyboard.nextDouble(); double result; // the average is called // the return value is assigned to "result" result=average(num1, num2); System.out.printf(" The result is %f", result); // calling the perimeter method with sides double perimeter = perimeter(num1,num2); System.out.printf(" Perimeter of Rectangle is %.2f ",perimeter); }//end of main }//end of Methods2 I Get this error message in JGrasp "compilation failed but no errors were detected. Check for non clickable errors in the compile output" any fix on either code so it will work on Jgrasp for my homework? Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
