这对我来说在逻辑上是完全合理的,但是我的输出是数组随机数的最后一个数字。我怀疑变量会不断被放入正在打印的内容中。 我们将非常感谢您的见解。
public class HiitClock extends AsyncTask<String, Void, String> {
private final String LOG_TAG = HiitClock.class.getSimpleName();
private TextView clock;
private StopWatch stopWatch;
public HiitClock(TextView clock, StopWatch sw){
this.clock = clock;
this.clockSegment = clockSegment;
this.roundSegment = roundSegment;
this.stopWatch = sw;
}
@Override
protected String doInBackground(String... params) {
stopWatch.start();
while(stopWatch.getState() == 1 || stopWatch.getState() == 2){
publishProgress();
}
return "done";
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
clock.setText(convertTime());
}
@Override
protected void onPostExecute(String result) {
// end of timer
clock.setText(result);
}
/*
* helper method for converting the time
* */
private String convertTime(){
long milli = stopWatch.getTime();
long sec = milli / 1000 ;
long min = sec / 60;
sec = sec % 60;
milli = milli % 100;
return String.format("%02d:%02d:%02d", min, sec, milli);
}
}
答案 0 :(得分:0)
试试这个
public static int[] sortArray(int[] preSortArray, int numberOfValues) {
int temp;
for(int i=0; i < numberOfValues.length-i; j++) {
for(int j=1; j < numberOfValues.length-i; j++){
if(numberOfValues[j-1] > numberOfValues[j]);
swap = preSortArray[tempNumTwo];
preSortArray[j-1] = numberOfValues[j];
preSortArray[tempNum] = swap;
}
}
}return preSortArray;
}
答案 1 :(得分:0)
首先,您的交换代码是错误的!第二行应该是:
project2
其次,您对冒泡排序的实现也是错误的。在每次迭代中,我们都不会将第i个数字与第j个数字进行比较!我们比较两个连续的数字。以下是您的代码的更正版本:
preSortArray[i] = preSortArray[tempNumTwo];