java - .class expected error in my method and sometimes missing return statement error -
i new java , don't know why piece of code isn't compiling. isn't return result. suggestions?
public static char isprime(int x) { for(int y=2;y<x;y++) char result = 'r'; if(x%y==0) result = 't'; else result = 'f'; return result; }
or
public static char isprime(int x) { char result = 'r'; for(int y=2;y<x;y++) if(x%y==0) result = 't'; else result = 'f'; return result; }
if use braces, code this:
public static char isprime(int x) { for(int y=2;y<x;y++) { char result = 'r'; } if(x%y==0) { result = 't'; } else { result = 'f'; } return result; }
as can see, variables y , result visible in loop
Comments
Post a Comment