数字の場所を特定し、実行するループの数を決定するにはどうすればよいですか?例えばJavaで数字の '場所'を取得する方法(例:数万、数千など)
私は、配列int[] a= {123,342,122,333,9909}
とint max = a.getMax()
を持っている場合、我々は、私は千番目の場所である9909の数の桁値を、取得したい値9909.を取得します。例えば
...ここ
(number place value,number of loop to run)
(one,1 time)
(tenth,2 time)
(hundred,3 time)
(thousand,4 time)
(ten thousand,5 time)
(hundred thousand,6 time)
は
public static int getMax(int[] t,int n){
int maximum = t[0]; // first value of the array
int index = 0;
int div=1;
int numSpace=0;
int valueTester=34;
boolean done=false;
for (int i=1; i<n; i++) {
if (t[i] > maximum) {
maximum = t[i]; // maximum
index = i; // comparing index
}
}
while(done==false){
if (valueTester==0){
done=true;
}
else{
valueTester=(maximum/div) % 10;
div=div*10;
numSpace++;
}
}
return numSpace;
}
}
あなたは可能性があなたの質問をフォーマットするには、少なくとも試みを。 –