There is either something broken about the tools you are using, or the process you are using. (For example, you might have made a mistake with your classpath.)
At any rate, your program works for me, as demonstrated by the following:
[steve@newbox tmp]$ cat > app.java
class app
{
public static void main(String[] args) {
double accounts[];
accounts=new double[100];
accounts[2]=1225.33;
System.out.println("Account 2 is overdue by $"+accounts[2]);
}
}
[steve@newbox tmp]$ javac app.java
[steve@newbox tmp]$ java app
Account 2 is overdue by $1225.33
[steve@newbox tmp]$
For the record, this is with Java 8 tools ... and I haven't set the CLASS_PATH environment variable. (Hence, java
and javac
will just be using the current directory as the classpath.)
The only other possibility I can think of is that your original code has a nasty homoglyph in (maybe) the main
identifier, that causes the java
command to not see the method. There is a chance that StackOverflow will silently "fix" homographs in Questions and Answers. (It certainly seems to "fix" dodgy control codes.)