简单帮你实现了下,有问题再追问。
public static String sortArray(String str) {
StringBuffer letterBuffer = new StringBuffer();
StringBuffer numberBuffer = new StringBuffer();
for(char c : str.toCharArray()) {
if(c >= '0' && c <= '9')
numberBuffer.append(c);
else
letterBuffer.append(c);
}
return letterBuffer.toString() + numberBuffer.toString();
}
public static void main(String[] args) {
// test
String test = "1a2b3c4d";
System.out.println(sortArray(test));
}
给你个简单思路,读取每一个字符,如果是字母就加在一个StringBuffer上,如果是数字加在另外一个StringBuffer上,最后把两个StringBuffer加起来就行了,保持顺序不变
package com;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "23ndkds34";
char ch;
String buf;
StringBuffer buf1 =new StringBuffer();
StringBuffer buf2 =new StringBuffer();
StringBuffer buf3=new StringBuffer();
for(int i=0;i
buf = String.valueOf(ch);
if(buf.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")){
buf1= buf1.append(ch);
}
}
for(int j=0;j
buf = String.valueOf(ch);
if(buf.matches("^[A-Za-z]+$")){
buf2= buf2.append(ch);
}
}
buf3= buf1.append(buf2);
System.out.println(buf3);
}
}
public class Sb {
static String s="1eqw23asd5ge893qr46";
static String c="abc";
static int h=s.length();
public static String getin(){
StringBuffer sb=new StringBuffer();
String p=s;
for(int j=0;j
System.out.println(m+"m的值");
for(int i=0;i<10;i++){
Integer hu=(Integer)i;
if(m.equals(hu.toString())){
sb.append(m);
}
}
p=p.substring(1);
}
return sb.toString();
}
public static void main(String args[]){
System.out.println(Sb.getin());
}
s为你要判断的字符串 希望采纳!