public class LuckyNames { public static boolean isPrime(int n){ int to = n / 2; for(int i=2; i<=to ;i++) if( n % i == 0) return false; return true; } public static int luckyAverage( String name){ int len = name.trim().length(); double factor = 100.0/ len; double luckyness = 0; for(int i = 0 ;i < len; i++){ int c = (int) name.charAt(i); if( isPrime(c)) luckyness += factor; } return (int) luckyness; } public static void main(String[] args){ System.out.println("SISCO:" + luckyAverage("SISCO") + "% lucky"); System.out.println("cake:" + luckyAverage("cake") + "% lucky"); System.out.println("Summer:" + luckyAverage("Summer") + "% lucky"); System.out.println("Virus:" + luckyAverage("Virus") + "% lucky"); } }