simple input/output program
ive been using c++ for a while but am having problems with my following code. i want to input 2 floating point values and then do 2 calculations on them. my problem is that it compiles but bypasses the second input and goes straight back to the prompt. but if i initialize length and width with values and dont ask for input the program works. can someone tell me what im doing wrong. thanks in advance
import java.io.*;
public class q4{
public static void main( String args[] )throws IOException
{
float l = 0.0F;
float w = 0.0F ;
System.out.print("Enter the length: ");
l = System.in.read();
System.out.print("Enter the width: ");
w = System.in.read();
perimeter(l,w);
area(l,w);
}
//a method for calculating the perimeter
public static void perimeter( float length, float width){
if( length >= 0.0 && length <= 20.0 ){
if( width >= 0.0 && width <= 20.0 )
System.out.println
("The perimeter of the rectangle is " + (( length * 2) + ( width * 2 )));
}
}
//a method for calculating the area
public static void area( float length, float width){
if( length >= 0.0 && length <= 20.0 ){
if( width >= 0.0 && width <= 20.0 )
System.out.println
("The area of the rectangle is " + (length * width));
}
}
}