Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error.....

 
archana keerti
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21119
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also please code tags as it makes your code much easier to read....
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One source of error is

there is no declaration of "X" at least not in the code you posted. And Java is case sensitive.
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, a semi colon on this line:



 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line will throw a compile error too.




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

 
Campbell Ritchie
Sheriff
Pie
Posts: 48957
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic