3 Replies - 1239 Views - Last Post: 30 October 2008 - 07:30 PM Rate Topic: -----

#1 CherylP  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 30-September 08

Basic If Statement Error!

Posted 30 October 2008 - 07:11 PM

WHY oh WHY am I getting this error? I will go ahead and post the entire thing, even though I am only getting the error on one line. I'm isolating it from the rest of the lines of code to help it pop out a little more.


import java.util.Scanner;
 
public class Pearce_Cheryl_03_03 {
	
	public static void main(String[] args) {
		
double area1; //Area of rectangle one
double area2; //Area of rectangle two
double length1; //Length of rectangle one
double length2; //Length of rectangle two
double width1; //Width of rectangle one
double width2; //Width of rectangle two 
String input; //To hold user's input

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the length of the first rectangle, then press enter.");
length1 = keyboard.nextDouble();

System.out.println("Enter the width of the first rectangle, then press enter.");
width1 = keyboard.nextDouble();

area1 = (length1 * width1);

System.out.println("The area of the first rectangle is "+ area1 +".");

System.out.println("Enter the length of the second rectangle, then press enter.");
length2 = keyboard.nextDouble();

System.out.println("Enter the width of the second rectangle, then press enter.");
width2 = keyboard.nextDouble();

area2 = (length2 * width2);

System.out.println("The area of the second rectangle is " + area2 + ".");


if (area1  > area2)
	System.out.println("The first rectangle has a greater area than the second.");




if (area 1 < area2) //Error here for "(" expected, not a statement, and; expected
		System.out.println("The second rectangle has a greater area than the first.");




if (area1 == area2)
		System.out.println("The area of both rectangles is the same!");
	}
}




This is quite frustrating. Any help is appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Basic If Statement Error!

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5305
  • View blog
  • Posts: 27,198
  • Joined: 10-May 07

Re: Basic If Statement Error!

Posted 30 October 2008 - 07:13 PM

View PostCherylP, on 30 Oct, 2008 - 10:11 PM, said:

if (area 1 < area2) //Error here for "(" expected, not a statement, and; expected
		System.out.println("The second rectangle has a greater area than the first.");


area 1 is not the same as area1

Sometimes it just takes a fresh pair of eyes.
Was This Post Helpful? 1
  • +
  • -

#3 CherylP  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 30-September 08

Re: Basic If Statement Error!

Posted 30 October 2008 - 07:27 PM

Wow. I don't know you, but I think I'm in love! ; ) Thank you! Works perfect!
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Basic If Statement Error!

Posted 30 October 2008 - 07:30 PM

exactly, area1 is not the same as area 1...you have to write variables exactly the same way they were declared..and also a space is not allowed in class names, method names and variable names...also java is case sensitive...a cool thing to do is to install eclipse, its an IDE very good to use for java..with eclipse it will be very easy to find typo mistakes and also there are a lot of automations going on..you'll like it..check it out and good luck ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1