• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newby - W/ Simple Compiling Problem  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I'm trying to do an exercise from a book that doesn't have the answer listed. The final line I'm trying have on on the print out is "DooBeeDooBeDo". I get a boolean error for the last part that I made bold.

The error is:
DooBee.java:12: cannot find symbol
symbol : method If(boolean)
location: class DooBee
If(x==4);{
^
1error

I guess that I am trying to use an int as a boolean, and my code is below. Any suggestions on how to fix it? Your help is greatly appreciated.


public class DooBee
{
public static void main (String[] args)
{
int x =1;
while(x<4){
System.out.print("Doo");
System.out.print("Bee");
x=x+1;
}

If(x==4); {
System.out.print("Do");


}
}
}
 
village idiot
Bartender
Posts: 1211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric, your problem lies in the fact that you capitalized if. I tried your code and it worked with a lower case i in the if statement. You aren't using an integer as a boolean, you are using the == operator to compare two integer values. The result of the comparison returns a boolean.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


No need for semicolon...
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

I think you have already had the answer to your question, and Lorand Komaromi has also given you the answer to the other question you didn't ask. I presume you understand what that last reply means?
 
Eric Ruiz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coding is very precise. You can't be off a little. Thank you to all, and I do understand the last semi-colon comment.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done. Coding has to be precise; the compiler is designed to be as fussy as possible, but errors can slip through. Remember: the longer it takes for an error to show up, the more opportunity it has to do harm and damage. A program which doesn't run can't do any harm, but a program which runs and produces the "wrong" answer can do no end of damage.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!