1

I am using a Mac osx 10.10.5 Yosemite, and I am trying to run my short Java program using Terminal. I first entered: "emacs Salary.java". Then: "javac /Users/username/Documents/Salary.java". And finally: "java Salary". It created a .class file for my java program, yet it says "

Error: Could not find or load main class Salary"

after I try running it. Am I doing something wrong? I checked the directories and it's in the correct place. The code is provided below, thank you in advance:

    public class Salary {

    public static void main (String [] args) {
        int hourlyWage = 20;

        System.out.print("Annual salary is: ");
        System.out.println(hourlyWage * 40 * 50);

        System.out.print("Monthly salary is: ");
        System.out.print((hourlyWage * 40 * 50) / 12);

        return;
    }
}
Shakeer Mirza
  • 5,054
  • 2
  • 18
  • 41
Manolo Ribera
  • 103
  • 1
  • 4
  • 8
  • 2
    `java -cp . Salary` (assuming `Salary.class` is in your current working directory) – Elliott Frisch Jan 19 '17 at 03:48
  • Possible duplicate of [What does "Could not find or load main class" mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Baby Jan 19 '17 at 03:50
  • Sorry I over analyzed my problem, I forgot to do cd Documents before all of the steps I provided, it works now. – Manolo Ribera Jan 19 '17 at 04:06

0 Answers0