Java Error: Could not find or load main class -
package src.sheet1.question1; class onefourtwoone { public static void main(string[] args) { assert args.length == 1; int x = integer.parseint(args[0]); system.out.print(x); while(x != 1) { x = next(x); system.out.print(" " + x); }; } static int next(int x) { return ((x % 2) == 0) ? (x / 2) : (3*x + 1); } }
when input :java onefourtwoone in terminal, here occurs error: error: not find or load main class onefourtwoone how can run it?
java cannot run class because in package. java expects package name matched path file.
create directory structure looks this:
src +-sheet1 +-question1 +-onefourtwoone.java
and compile class onefourtwoone.class
. switch parent directory of src
, , execute command
java src.sheet1.question1.onefourtwoone
Comments
Post a Comment