希望する動作:数字を1桁(2桁)ではない1桁からlim
ループを使用して範囲内の別個の数字を持つ数字を検索する
特定の問題:プログラムは無限ループで実行されます。
これは私がすでに行ったことです。それは動作していません。私は各ステップで値を印刷しようとしましたが、infinteループで1を与え続けます。
どうしたのですか?
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
double limit=sc.nextDouble(); // reading the range of numbers from 0 to limit-digit number
int count=0,total=0;
int lim=(int)(Math.pow(10.0,limit)); //setting range from 0 to 10^limit
System.out.println(lim);
for(int i=1;i<lim;i++) {
Set<Integer> set = new HashSet<Integer>(); //making a hash set to include the unique elements
System.out.println(i);
while (i > 0) {
int tempVal = i % 10; //each digit is extracted and stored in hash set if unique
set.add(tempVal);
i = i/10;
count++;
//System.out.println(count);
}
count+=1;
if(count==set.size())
{
total++;
}
count=0;
}
System.out.println(total);
}
デバッガを使用してください。 – Jens
デバッグヘルプを求める質問(「なぜこのコードは動作しませんか?」)には、目的の動作、特定の問題またはエラー、およびその中で再現するために必要な最短コード質問自体。明確な問題文がない質問は、他の読者にとって有用ではありません。参照:[mcve]を作成する方法 – GhostCat
コードにコメントを追加できますか? –