• Post Reply Bookmark Topic Watch Topic
  • New Topic

strange output  RSS feed

 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




question;i compiled the above mentioned code and it compiled fine but when i ran i got


at K.m(Gg.java:10)
at Gg.main(Gg.java :20)



multiple times.can anyone plese help me understand it.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rrohit rakesh upadhyay wrote:question;i compiled the above mentioned code and it compiled fine but when i ran i got
at K.m(Gg.java:10)
at Gg.main(Gg.java :20)
multiple times.

No. You almost certainly got an Error (StackOverflowError I suspect) that included those lines.

And the reason is that you have an infinite loop. In Gg.main() you create a K and then run its m() method. That checks if i is < 2, which it is, so it calls Gg.main(), which creates another K and runs its m() method....

Winston

PS: Next time, please UseCodeTags (←click). I've added them for you this time; see how much better it looks?
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for clearing out that doubt,Winston.However i have one more doubt.



when i ran the above code i got the following error.



illegal start of expression

static int i;
^



can you explain why.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rrohit

Look where you have declared i in the code. Does having a static variable make sense there?
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is declaring a static variable inside a method is illegal?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got it!
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you james and winston.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rrohit rakesh upadhyay wrote:thank you james and winston.

You're most welcome.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!