Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

'class' or 'interface' expected  RSS feed

 
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
 
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().
 
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");
}
}
}
 
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!