-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
156 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/example/helloandroid/Main9Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.helloandroid; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.widget.TextView; | ||
|
||
public class Main9Activity extends AppCompatActivity { | ||
private TextView textView18; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main9); | ||
textView18 = (TextView)findViewById(R.id.textView18); | ||
|
||
int[] data={3,44,38,5,47,15,36,26,27,2,46,4,19,50,48};//数据 | ||
|
||
//输出数据看看 | ||
textView18.setText(textView18.getText()+"Go "); | ||
for (int data_i=1;data_i<data.length;data_i++){ | ||
textView18.setText(textView18.getText()+""+String.valueOf(data[data_i])+","); | ||
Log.i("data", String.valueOf(data[data_i])+","); | ||
} | ||
textView18.setText(textView18.getText()+"\n\n"); | ||
|
||
|
||
//冒泡开始 | ||
int i,j; | ||
for (i = data.length;i>1;i--){ | ||
//textView18.setText(textView18.getText()+"\n"+"i>1"); | ||
Log.i("i", String.valueOf(i)); | ||
for (j=1;j<i;j++){ | ||
Log.i("j", String.valueOf(j)); | ||
if(j+1<i) { | ||
if (data[j] < data[j + 1]) { | ||
int tmp = data[j]; | ||
data[j] = data[j + 1]; //交换 | ||
data[j + 1] = tmp; | ||
} | ||
} | ||
} | ||
|
||
for (int data_i=1;data_i<data.length;data_i++){ | ||
textView18.setText(textView18.getText()+""+String.valueOf(data[data_i])+","); | ||
} | ||
textView18.setText(textView18.getText()+"\n"); | ||
} | ||
//冒泡结束 | ||
|
||
textView18.setText(textView18.getText()+"\nOK "); | ||
for (int data_i=1;data_i<data.length;data_i++){ | ||
textView18.setText(textView18.getText()+""+String.valueOf(data[data_i])+","); | ||
} | ||
textView18.setText(textView18.getText()+"\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".Main9Activity"> | ||
|
||
<ScrollView | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/textView18" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="==程序输出==\n" /> | ||
</LinearLayout> | ||
</ScrollView> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |