package samples.string.japanese;
public class ZenkakuAlphabetToHankakuAlphabet {
public static String zenkakuAlphabetToHankaku(String s) {
StringBuffer sb = new StringBuffer(s);
for (int i = 0; i < sb.length(); i++) {
char c = sb.charAt(i);
if (c >= 'a' && c <= 'z') {
sb.setCharAt(i, (char) (c - 'a' + 'a'));
} else if (c >= 'A' && c <= 'Z') {
sb.setCharAt(i, (char) (c - 'A' + 'A'));
}
}
return sb.toString();
}
public static void main(String[] args) {
System.out.println(zenkakuAlphabetToHankaku("☆Javaプログラミング☆"));
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme