这道题难吗?

sonny99 2004-12-30 04:59:53
给定一组字符串,编程对该组字符串按字典序增序排序。
哪个大哥能把代码写出来
感激不尽!!!!!
...全文
55 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sonny99 2004-12-30
  • 打赏
  • 举报
回复
对吗?我看不懂,错了就不及格了哟。谢谢!
vgvg 2004-12-30
  • 打赏
  • 举报
回复
public class TestS{
public static void main(String arg[]){
String[] a={"gsgsh","hsdhs","hshshrttttttttt","tttttt","aaa"};
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
System.out.println();
bubbleSort(a);
for(int k=0;k<a.length;k++)
System.out.print(a[k]+" ");
}
public static void bubbleSort(String[] array)
{
for(int i = 0; i < array.length; i++)
{
for(int j = array.length - 1; j > i; j--)
{
if(array[j].compareTo(array[j-1])<0)
{
swap(array, j, j-1);
}
}
}
}


private static void swap(String[] array, int left, int right)
{
String temp = array[left];

array[left] = array[right];
array[right] = temp;
}
}
sonny99 2004-12-30
  • 打赏
  • 举报
回复
我一点都不懂,能不能把代码全部写出来啊。
网络 方面的问题你可以问我的,都可以帮你
classjava 2004-12-30
  • 打赏
  • 举报
回复
用compareTo();就可以比较了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧