给一个不多于5位的正整数,要求1,求出它是几位数!2分别打印出每一位数字!3按逆序打印出各数字!

1个回答

  • package comm.db2;

    /**

    * @author jifei

    *

    */

    public class Order {

    String str1 = "";

    int tempi = 0;

    public Order() {

    }

    public Order(String temp) {

    str1 = temp;

    tempi = str1.length();

    }

    /**

    * 得到最小的

    *

    * @param temp

    * @return

    */

    public String getMin(String temp) {

    temp = str1;

    char ch[];

    ch = temp.toCharArray();

    int len = ch.length;

    int arry1[] = new int[len];

    int ii = 0;

    for (int i = 0; i < len; i++) {

    arry1[i] = Integer.parseInt(String.valueOf(ch[i]));

    }

    ii = arry1[0];

    for (int i = 0; i < len; i++) {

    if (ii >= arry1[i]) {

    ii = arry1[i];// 小的 赋给11

    }

    }

    return ii + "";

    }

    /**

    * 得到除去最小的字符串

    *

    * @param temp

    * @param temp2

    * @return

    */

    public String reFirst(String temp,String temp2) {

    temp = temp.replaceFirst(temp2,"");

    str1 = temp;

    System.out.println(temp);

    return temp;

    }

    public String getOrder() {

    String str = "",minstr = "";

    String tempstr = "";

    tempstr = str1;

    for (int i = 0; i < tempi; i++) {

    minstr = getMin(tempstr);

    tempstr = reFirst(str1,minstr);

    str += "" + minstr + ",";

    }

    return str;

    }

    /**

    * @param args

    */

    public static void main(String[] args) {

    Order order = new Order("4810223");

    System.out.println(order.getOrder());

    }

    }