package ai;
import *;
public class wo {
public static void main(String[] args) {
String[] stringArray;
//定义字符串
stringArray = new String[20];
//定义字符串的大小
int i;
for (i = 0; i < stringArray.length; i++)
//通过for循环对字符串赋值
{
System.out.println("Please input data for stringArray " + i);
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
stringArray[i] = in.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
}
int j, m;
int l = stringArray.length;
//求字符串的长度
for (j = 0; j < l - 1; j++) {
for (m = j + 1; m < l; m++) {
if (Integer.parseInt(stringArray[j]) >
Integer.parseInt(stringArray[m])) {
//这里要强制转换成数字,而不能是对象的比较
String t = stringArray[j];
stringArray[j] = stringArray[m];
stringArray[m] = t;
//这里“t”前面不要string
注意string!=stering
}
}
}
System.out.println("排序后的结果:");
for (j = 0; j < stringArray.length; j++) {
System.out.print(stringArray[j] + " ");
int y=1;
y=y+j;
//相当一个计数器
if(y%5==0)System.out.println("");
//换行作用
}
}
}