Scanner s = new Scanner(System.in); int times; times = s.nextInt(); //brings in an int from commandline times = times < 0 ? -times : times; int notes = times++; if (times-- > 5 || notes == times) notes *= (times-2); else if (times%4==1 && notes < times) notes += times - 1; if (-times > -notes) System.out.println(notes); else System.out.println(times);