java题:数组排序;要求:数组长度不定,是用Scanner从控制台动态录入,且不一定都是数字;
展开全部
你看看这个是不是符合你的要求
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList list = new ArrayList();
String temp = "";
while(true){
temp = br.readLine();
if(temp.equals("exit")){
break;
}
list.add(temp);
}
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
展开全部
这个怎么样呀,希望可以帮到你。
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
while(scanner.hasNext()) {
String line = scanner.next();
System.out.println(line);
if(line != null && line.equals("exit"))
break;
list.add(line);
}
Iterator<String> it = list.iterator();
while(it.hasNext()) {
System.out.print(it.next() + " ");
}
}
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
while(scanner.hasNext()) {
String line = scanner.next();
System.out.println(line);
if(line != null && line.equals("exit"))
break;
list.add(line);
}
Iterator<String> it = list.iterator();
while(it.hasNext()) {
System.out.print(it.next() + " ");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询