• Post Reply Bookmark Topic Watch Topic
  • New Topic

missing return statement error  RSS feed

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

This is my second day of learning Java. Really sorry to bother you guys but when I try to compile the below program I am getting "missing return statement" error (line 24) and indicating it is the "}"

public class BeerSong {
public static Void main (String [] args) {
int beerNum = 99;
String word = "bottles";

while (beerNum > 0) {

if (beerNum == 1){
word = "bottle";
}
System.out.println(beerNum + " " + word + " of beer on the wall, ");
System.out.println(beerNum + " " + word + " of beer.");
System.out.println("Take one down and pass it around, ");
beerNum = beerNum - 1;

if(beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall.");
} else {
System.out.println("No more bottles of beer on the wall");
}

}

}

}

I am sorry if I made an obvious mistake, which I can't help but feel that I did, but I have been trying to figure this for the last one hour.

Regards

Rama
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rams Naraparaju wrote:
I am sorry if I made an obvious mistake, which I can't help but feel that I did, but I have been trying to figure this for the last one hour.


You accidentally made the return type "Void" instead of "void". The first is a reflection type, and the second means that nothing is to be returned -- and the correct signature for the main() method.

Henry
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled your code and did not get the error you specified. Instead I got this error:
Java is case sensitive. "Void" should be "void" Also, it really helps when posting code to UseCodeTags. Here is what your code looks like when using code tags and properly indenting the code:
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Rams Naraparaju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jesper..it's nice to be part of this wonderful community. Thank you Henry and Tom, it is compiling now...appreciate your time. Tom don't know how to use code tags...sorry...will figure it out the next time I submit.
You all have a great day/night/afternoon/evening

regards

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