public class SampleGame {
public static final int MAX_VALUE = 10;
public static void main(String[] args) {
SampleGame sampleGame = new SampleGame();
if (args.length > 0){
final int num = Integer.parseInt(args[0]);
System.out.println("あなたの入力は"+num+"ですね");
final int answer = sampleGame.createAnswer();
if (answer == num){
System.out.println("おめでとう");
} else {
System.out.println("残念!答えは"+ answer + "です" );
}
}
}
private int createAnswer(){
return (int) (Math.random()*MAX_VALUE);
}
}
コードの解析は、非常に簡単です。図1で示すとおり、解析対象となるプロジェクト、パッケージ、ソースコードを選択し、右クリックして「CheckCode With PMD」を選択するだけです。