こう書いてみた
package sample;
import java.util.regex.Pattern;
public class Nabeatsu {
private String number;
private int ahoNumber;
public Nabeatsu(String number) {
this.number = number;
this.ahoNumber = 3;
}
public Nabeatsu(String number, String ahoNumber) {
this.number = number;
this.ahoNumber = Integer.parseInt(ahoNumber);
}
public String play() {
StringBuffer buf = new StringBuffer();
for (int i = 1; i < Integer.parseInt(this.number) + 1; i++) {
buf.append(guess(i) == true ? "AHO" : (new Integer(i).toString()));
buf.append(" ");
}
return buf.toString();
}
private boolean guess(int number) {
if (0 == number % this.ahoNumber) {
return true;
}
return Pattern.compile(
".*" + (new Integer(this.ahoNumber).toString()) + ".*")
.matcher(new Integer(number).toString()).matches();
}
/**
* @param args
*/
public static void main(String[] args) {
Nabeatsu nabeatsu = new Nabeatsu(args[0]);
System.out.println(nabeatsu.play());
}
}
No comments:
Post a Comment