|
-
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));
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks