java - Why doesn't the return of my method work? -
i have assignment java class i'm taking in college. i'm supposed write program gets length , width user , display perimeter of rectangle. then, needs return area. have written source code it, ide, eclipse keeps saying i'm using voided method, therefore, can't return.
here source code:
/** jason delgado * spc id: 2051577 * program gets length , width of rectangle user, displays perimeter, * , returns area. */ package com.delgado; import javax.swing.joptionpane; //gets joptionpane class import java.text.decimalformat; //gets decimalformat class public class rectangle { public static void main(string[] args) { double length; // holds length double width; // holds width string input; // holds input double area; // holds area decimalformat formatter = new decimalformat("#0.00"); // holds format input = joptionpane.showinputdialog("enter length of rectangle: "); length = double.parsedouble(input); input = joptionpane.showinputdialog("enter width of rectangle: "); width = double.parsedouble(input); area = getarea(length, width); /** method getarea() displays perimeter of rectangle , returns area * @perm num1 holds length * @perm num2 holds width * @return returns area of rectangle */ public static double getarea(double num1, double num2){ double perimeter; // holds perimeter perimeter = (num1 * 2) + (num2 * 2); joptionpane.showmessagedialog(null, "the perimeter of rectangle is: " + formatter.format(perimeter)); return num1 * num2; } }
}
edit since you've added code, have edited answer:
it looks getarea
method inside main. move outside.
public class rectangle { public static void main(string[] args) { .... } public static double getarea(double num1, double num2) { ... } }
Comments
Post a Comment