Where is the error in my code?
Posted
by
Lulu Larson
on Stack Overflow
See other posts from Stack Overflow
or by Lulu Larson
Published on 2012-04-04T05:12:33Z
Indexed on
2012/04/04
5:29 UTC
Read the original article
Hit count: 273
java
/** Yields: a String that contains each capital Letter (in 'A'..'Z') whose representation is prime */
public static String primeChars() {
String s = "";
// inv: s contains each capital in "A'..c-1 whose representation is prime
for (char c = 'A'; c <= 'Z'; c=(char)(c+1)) {
if (Loops.isPrime((int)c) == true) {
s= s+1;
}
}
// s contains each capital in 'A' ..'Z' whose rep is a prime
return s;
}
© Stack Overflow or respective owner