字符串 s ="1,3,21,5,12,4"从小到到排序
class A{
String s = "1,3,21,5,12,4";
for(int i=0;i<s.length();i++){
for(int j=1;j<s.length()-1;j++){
String temp;
if(s(j-1)>s(j)){
temp=s(j-1);
s(j-1)=s(j);
s(j)=temp;
}
}
for(int k=0;k<s.length();k++){
system.out.println(s(i));
}
}
那位大哥分析这段代码哪里报错?
}
class A{
String s = "1,3,21,5,12,4";
for(int i=0;i<s.length();i++){
for(int j=1;j<s.length()-1;j++){
String temp;
if(s(j-1)>s(j)){
temp=s(j-1);
s(j-1)=s(j);
s(j)=temp;
}
}
for(int k=0;k<s.length();k++){
system.out.println(s(i));
}
}
那位大哥分析这段代码哪里报错?
}
解决方案 »
- eclipse与tomcat集成问题
- 谁用过eclipse的JIBX插件?
- spring quartz每个jobdetail都需要配置?(结贴率100%)
- global-forwards和froward有什么区别啊?
- Hibernate 的 DetachedCriteria 多表查询问题?
- 表单输入中文出现乱码,刷新后没有乱码了,怎样解决?求教。
- 哪位有j2ee的qq群呢?
- WEBLOGIC如何访问
- hibernate高手请进,exception setting property value with CGLIB 问题
- 用main函数来测试ejb的sessionBean,运行到context = new InitialContext()时,出现如下错误.......
- 求助!!!!!数据库连接报错
- java 首页地址路径问题
int [] str={1,3,21,5,12,4}
int s[] = { 1,3,21,5,12,4 };
for(int i=0;i <s.length;i++){
for(int j=1;j <s.length-1;j++){
int temp;
if(s[j-1]> s[j]){
temp=s[j-1];
s[j-1]=s[j];
s[j]=temp;
}
}
for(int k=0;k <s.length;k++){
system.out.println(s[i]);
}
}
public static void main(String args[]){
String s = "1,3,21,5,12,4";
String str [] = s.split(",");
for(int i=0 ; i<str.length; i++){
int a = Integer.parseInt(str[i]);
for(int j=0 ; j<str.length; j++){
int b = Integer.parseInt(str[j]);
String temp;
if(a<b){
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
for(String ww:str){
System.out.println(ww);
}
}
}