GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes compilation error..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error....." Watch "compilation error....." New topic
Author

compilation error.....

archana keerti
Greenhorn

Joined: Feb 03, 2009
Posts: 20
hi ,
please anyone could help me...i have a problem in the compilation of the below given program.

public class puzz
{
public static void main(String args[])
{
dog[] d=new dog[6];
int x=0;
int y=1;
int result=0;

while(x<6)
{
dog[x]=new dog[];
d[x].v=y;
y=y*10;
x=X+1;
}
x=6;
while(x>0)
{
x=x-1;
result=result+d[x].do(x);
}
System.out.println("result is"+result)

}

}


class dog
{
int v;
public int do(int f)
{
if(v>100)
{
return v*f;

}
else
{
return v*(5-f);
}
}
}


the required output for the program is 543345.


when i compile i get some error messages like,illegal start of type,<identifier>expected, ; expected.....
i couldn't find where i am wrong.....
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

when i compile i get some error messages like,illegal start of type,<identifier>expected, ; expected.....
i couldn't find where i am wrong.....


Generally, with these types of error, it can occur at the line previously -- I would examine the line mentioned by the compiler (and the lines before).... It could be something as simple as a missing close brace or something.


And BTW, if you expect us to further help, it would be great to actually paste the actual compile error.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Also please code tags as it makes your code much easier to read....


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

One source of error is

there is no declaration of "X" at least not in the code you posted. And Java is case sensitive.


SCJP, SCWCD.
|Asking Good Questions|
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

also, a semi colon on this line:




[List of FAQs] | [Android FAQ] | [Samuh Varta]
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
This line will throw a compile error too.




In addition, you cannot name a method "do" as its a reserved keyword(??)

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Although it is very helpful and interesting to try guessing how many compiler errors this class will produce, it is really for the original poster to say how many errors they expect, and people replying to agree or disagree. Look at one of our FAQ. The original poster will learn a lot more that way.
 
GeeCON Prague 2014
 
subject: compilation error.....