what's wrong with code? Rectangle
Code java:
import java.util.Scanner;
public class Retangle{
Scanner input=new Scanner(System.in);
public static void main(String args[]){
double length;//The rectangle's length
double width;//The rectangle's width
double area;//The rectangle's area
Scanner input=new Scanner(System.in);
length=getLenth();// get the rectangle's from the user
width=getWidth();//get the rectangle's from the user
area=getArea(length,width);//get the rectangle area
displayData(length,width,area);//display the rectangle's area
}
public static double getLenth(){
double length=0.0;
System.out.println("Please enter the length:");
length=input.nextDouble();
return length;
}
public static double getWidth(){
double width=0.0;
System.out.println("\nPlease enter the Width:");
width=input.nextDouble();
return width;
}
public static double getArea(double length,double width){
return length*width;
}
public static void displayData(double length,double width,double area){
System.out.println("\nThe area is:"+area);
}
}
Re: what's wrong with code? Rectangle
Hi and welcome.
Please see the announcements page for the use of code tags when posting code.
You tell us what is wrong with the code. If you have any questions feel free to ask them.
Re: what's wrong with code? Rectangle
This seemed to make it work
Code Java:
static Scanner input=new Scanner(System.in);
I think it's cause it's outside the main but I'm not sure.
Also please follow what jps has said.