Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'class' or 'interface' expected

 
Christopher Kirkland
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I am currently learning java programming and stuck on one of the tutorials in this book.

the code:
public class beersong{
public static void main (String[] args) {
int beerNum= 99;
string word ="bottles";
while (beerNum >0 ) {
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");
system.out.println("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");
}
}
}
}
when compiled I get thease problems:
C:\Documents and Settings\Chris\app\beersong\beersong.java:20: 'class' or 'interface' expected
}
^
C:\Documents and Settings\Chris\app\beersong\beersong.java:20: 'class' or 'interface' expected
}
^
2 errors
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got one too many closing braces.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to preempt your next question.

Java is case sensitive. Use String not string and System.out.println() not system.out.println().
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christopher Kirkland:
hello,
I am currently learning java programming and stuck on one of the tutorials in this book.

the code:
public class beersong{
public static void main (String[] args) {
int beerNum= 99;
string word ="bottles";
while (beerNum >0 ) {
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");
system.out.println("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");
}
}
}
}
when compiled I get thease problems:
C:\Documents and Settings\Chris\app\beersong\beersong.java:20: 'class' or 'interface' expected
}
^
C:\Documents and Settings\Chris\app\beersong\beersong.java:20: 'class' or 'interface' expected
}
^
2 errors


I can see the following errors in above code:

1. When you open a bracket you need to close the bracket. In above code at line no 20 there is an extra bracket "}" remove it and compile.

2. Still you will get compilation errors. Java is case sensitive. So instead of "string" use "String" at line no 4.

3. Replace all "system" to System.

Now it will get compiled. Here is the code looks after correcting:

public class beersong{
public static void main (String[] args) {
int beerNum= 99;
String word ="bottles";
while (beerNum >0 ) {
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");
System.out.println("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");
}
}
}
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case sensitive!!!
 
Christopher Kirkland
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thak you I got it working
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic