aspose file tools*
The moose likes Beginning Java and the fly likes 'class' or 'interface'  expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Watch " New topic
Author

'class' or 'interface' expected

Christopher Kirkland
Greenhorn

Joined: Aug 10, 2005
Posts: 2
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

Joined: Aug 05, 2005
Posts: 3446
    
  12
You've got one too many closing braces.


Joanne
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
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

Joined: Sep 20, 2003
Posts: 1704
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

Joined: Jul 29, 2005
Posts: 60
Java is case sensitive!!!
Christopher Kirkland
Greenhorn

Joined: Aug 10, 2005
Posts: 2
Thak you I got it working
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'class' or 'interface' expected