(用最简单的方法) 有一个数组里有N个数,现在要你显示以第一位为1的在一列,然后空格第一位为2的在一列,然后空格。。第一位为n的在一列,然后空格例子:23 2 3 234 365 564 12 13 34 35
结果:
12
132
2343
34
35
365564

解决方案 »

  1.   

    int[] intArray = {10,100,1000,10000,100000,1000000};
    int[] testArray = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35};
    int num;
       num = testArray.length;
    for(int i = 1;i<=9;i++){
        if (num >0){
        System.out.println(i + ":");
        for(int j = 0;j < testArray.length;j++){
    for(int k = 0;k < 3;k++){
        if( testArray[j] / intArray[k] == i){
    System.out.println(testArray[j]);
    num--;
    break;
        }
    }
        }
    } }
      

  2.   

    int[] testArray = { 23, 2, 3, 234, 365, 564, 12, 13, 34, 35 };
    int[] flagArray ;
    flagArray = new int[testArray.length];
    for(int i = 0;i< testArray.length;i++){
        flagArray[i] = testArray[i];
    }
    for(int i=0;i < testArray.length;i++){
        while(flagArray[i] > 10){
    flagArray[i] /= 10;
        }
    }
    for(int i = 1;i<=9;i++){
        System.out.println(i + ":");
        for(int j = 0;j< flagArray.length;j++){
    if(flagArray[j] == i){
        System.out.println(testArray[j]);
    }
        }
    }
      

  3.   

    用charAt 循环 判断 1 是不是在 array[i] 第一位, 是的话, print , 遍历完print 空格。同理 2, 3,4,5,6....... 这样可以判断各个数开头的, 也可以是字符abc等开头的, array 数组里面的 元素如果是 23ab之类 也符合遴选规则可以选出
      

  4.   


    String[] str1 = {"12",  "13", "130", "1546", "12345", "23", "234", "25", "356", "32", "365 "};
    boolean judge2 = true;
    boolean judge3 = true;
    for(int i=0;i<str1.length;i++)
    {

    if((str1[i].indexOf("2")==0)&&judge2)
    {
    System.out.println("\n"+str1[i]+" ");
    judge2=false;
    }
    else if((str1[i].indexOf("3")==0)&&judge3)
    {
    System.out.println("\n"+str1[i]+" ");
    judge3=false;
    }
    else
    {
    System.out.println(str1[i]+" ");
    }
    }
    }
      

  5.   

    int[] tArr = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35,3453,223,6,744354,23131,5657,999,877,772,877};StringBuffer sb = new StringBuffer();
    StringBuffer sb1 = new StringBuffer(); //存储首位数字,用于判断
    for(int i=0;i<tArr.length;i++)
    {
    String t = tArr[i]+"";
    char tInx = t.charAt(0);


    if(sb1.toString().indexOf(tInx) == -1)
    {
    sb1.append(tInx);
    sb.append(t);

    for(int j=i+1;j<tArr.length;j++)
    {
    String s = tArr[j]+"";
    char sInx = s.charAt(0);
    if(tInx == sInx)
    {
    sb.append("\n");
    sb.append(s);
    }
    }
    } sb.append("\n\n");
    }

    System.out.print(sb.toString());
      

  6.   

    最简单?
    是指算法运行速度快还是代码短?
    这个应该是最短的
    int[] tArr = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35,3453,223,6,744354,23131,5657,999,877,772,877};
    String str[] = new String[tArr.length];
    for(int i=0;i<tArr.length;i++)
    str[i] = tArr[i]+"";
    Arrays.sort(str);
    for(int i=0;i<str.length;i++)
    System.out.println(str[i]);
      

  7.   

    改改,上面忘记空行了
    int[] tArr = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35,3453,223,6,744354,23131,5657,999,877,772,877};
    String str[] = new String[tArr.length];
    for(int i=0;i<tArr.length;i++)
    str[i] = tArr[i]+"";
    Arrays.sort(str);
    String prov = str[0];
    for(int i=0;i<str.length;i++){
    if(prov.charAt(0)!=str[i].charAt(0))
    System.out.println();
    System.out.println(str[i]);
    prov = str[i];
      

  8.   

    public class Test { public static void main(String argv[])
      {
        int[] tArr = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35,3453,223,6,744354,23131,5657,999,877,772,877};
        String[] teststr = new String[tArr.length];
        StringBuffer[] teststrbuf = new StringBuffer[9];
        for (int i=0;i<9;i++)
        {
         teststrbuf[i] = new StringBuffer();          
        }
        for (int i=0;i<tArr.length;i++)
        {
         teststr[i] = String.valueOf(tArr[i]);
        }
        for (int i=0;i<tArr.length;i++)
        {
         char head = teststr[i].charAt(0);
         switch(head){
           case '1': teststrbuf[0].append(teststr[i]+"\n");
                     break;
           case '2': teststrbuf[1].append(teststr[i]+"\n");
                     break;
           case '3': teststrbuf[2].append(teststr[i]+"\n");
                     break;
           case '4': teststrbuf[3].append(teststr[i]+"\n");
                     break;
           case '5': teststrbuf[4].append(teststr[i]+"\n");
                     break; 
           case '6': teststrbuf[5].append(teststr[i]+"\n");
                     break;
           case '7': teststrbuf[6].append(teststr[i]+"\n");
                     break;
           case '8': teststrbuf[7].append(teststr[i]+"\n");
                     break;   
           case '9': teststrbuf[8].append(teststr[i]+"\n");
                        break; 
         }
      }
        StringBuffer result = new StringBuffer();
        for (int i=0;i<9;i++)
        {
         if (teststrbuf[i].toString().length()>0)
         result.append(teststrbuf[i].toString()+"\n");
        
        }
        System.out.println(result.toString());
    }
    }
      

  9.   

    优化了一下,前面的程序多做了个循环,让大家见笑了
    public static void main(String argv[])
      {
        int[] tArr = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35,3453,223,6,744354,23131,5657,999,877,772,877};
        StringBuffer[] teststrbuf = new StringBuffer[9];
        for (int i=0;i<9;i++)
        {
         teststrbuf[i] = new StringBuffer();          
        }
        for (int i=0;i<tArr.length;i++)
        {
         String test = String.valueOf(tArr[i]);
         char head = test.charAt(0);
         switch(head){
           case '1': teststrbuf[0].append(test+"\n");
                     break;
           case '2': teststrbuf[1].append(test+"\n");
                     break;
           case '3': teststrbuf[2].append(test+"\n");
                     break;
           case '4': teststrbuf[3].append(test+"\n");
                     break;
           case '5': teststrbuf[4].append(test+"\n");
                     break; 
           case '6': teststrbuf[5].append(test+"\n");
                     break;
           case '7': teststrbuf[6].append(test+"\n");
                     break;
           case '8': teststrbuf[7].append(test+"\n");
                     break;   
           case '9': teststrbuf[8].append(test+"\n");
                        break; 
         }
      }
        StringBuffer result = new StringBuffer();
        for (int i=0;i<9;i++)
        {
         if (teststrbuf[i].toString().length()>0)
         result.append(teststrbuf[i].toString()+"\n");
        
        }
        System.out.println(result.toString());
    }
      

  10.   

    给大家个思路好了,不过不知道我的好不好。
    用2个stack,
    首先找首位为1的,打印,把不是的寸入其中一个stack中
    然后找首位为2的,打印,把不是的存入空的stack中
    ……
    直到两个stack都空了的时候就结束。这样好不???
      

  11.   

    其实"用最简单的方法" 这几个字是用来让你产生不安的感觉。
    最简单,是用笔写raojl的那样子。
    这倒道题目可以看作是对一维数组排序,规则是:按每个元素的第1位。可做如下解答。package yangyang.com;
    import java.util.*;class Cmp implements Comparator {
    public int compare(Object o1, Object o2) {
    if(((String)o1).charAt(0)<=((String)o2).charAt(0))
    return 0;
    else
    return 1;
    }
    }public class MyCheck { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int a[]={23,2,3,234,365,564,12,13,34,35};
    int i=0;
            ArrayList list=new ArrayList();
            for(i=0;i<a.length;i++)
             list.add(String.valueOf(a[i]));
            Comparator comp = new Cmp();
    Collections.sort(list, comp);
    for(i=0;i<list.size()-1;i++)
    {
    System.out.println(list.get(i));
    if (((String)list.get(i)).charAt(0)!=((String)list.get(i+1)).charAt(0))
    System.out.println();
    }
    System.out.println(list.get(i));

    }}
      

  12.   

    import java.util.*;class ComparableNum implements Comparable{
    private int i;
    ComparableNum(int i){
    this.i=i;
    }
    public char getChar(){
    return new String(""+i).charAt(0);
    }
    public String toString(){
     return ""+i;
    }
    public int compareTo(Object o){
    ComparableNum cn=(ComparableNum)o;
    String ostr=new String(""+cn.i);
    char ochar=ostr.charAt(0);
    char tchar=new String(""+this.i).charAt(0);
    if(ochar==tchar)
    return this.i<cn.i?-1:(this.i==cn.i?0:1);
    else 
    return ochar<tchar?1:(ochar==tchar?0:-1);
    }
    }
    public class PrintNum{
    private static int[] ints={23,2,3,234,365,564,12,13,34,35};
    //private static Map cnMap=new HashMap();
    public static ComparableNum[] toComparableNums(int[] ints){
    ComparableNum[] cns=new ComparableNum[ints.length];
    for(int i=0;i<ints.length;i++)cns[i]=new ComparableNum(ints[i]);
    return cns;
    }
    public static void main(String[] args){
    ComparableNum[] cns=toComparableNums(ints);
    Arrays.sort(cns);
    char c=cns[0].getChar();
    for(int i=0;i<cns.length;i++){
    char temp=cns[i].getChar();
    if(c!=temp){
    System.out.println();
    c=temp;
    }
    System.out.println(cns[i]);
    }
    }
    }
      

  13.   

    我也给个思路。不一定对把所有的数字串成字符串,如下:
    str=",23,2,3,234,365,564,12,13,34,35,"
    1开头的数字:匹配"/,1[0-9]*/gi"(我正则学的不好,不知道写的对不),把","换成"\n"
    不匹配的全部抹掉。
    2-9同
    一个for(int i=1; i<10; i++)循环得到9个这样的字符串,按顺序串起来,再把剩下的","替换成"\n"。其时最简单的应该是利用字符串排序了……而且保证不出错……
      

  14.   

    为什么我这样做不行,
    String[] a = {"134","133","13","32","34","52","5531"};
    int[] b = {1,2,3,4,5,6,7,8,9};
    for(int i =0 ; i<b.length ; i++){     for(int j=0 ; j<a.length ; j++){        if(a[j].codePointAt(0)==b[i]){
                  
                System.out.print(a[j]);        }     }
         System.out.println();
    }
      

  15.   

    codePointAt应该改成charAt(0);可是结果还是一样的.
      

  16.   

    insiku(tmd 结帖啊!!!)  的效率不是很高呀
      

  17.   

    public class Main {
    public static void main(String[] args) {
    Integer[] array = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35};
    int[][] test=new int[6][array.length];
    for(int i=0;i<array.length;i++) {
    //这行把第一个字符取出来转成STRING类型,直接用CHAR类型在下面会报错~-~
    String temp=String.valueOf(array[i].toString().charAt(0));
    //这行做赋值
    test[Integer.parseInt(temp)][i]=array[i];
    }
    for(int i=0;i<test.length;i++) {
    for(int j=0;j<array.length;j++) {
    if(test[i][j]==0) continue;
    else System.out.println(test[i][j]);
    }
    System.out.println();
    }
    }
    }
      

  18.   

    如果是按照题目要求不考虑排序的话,循环判断首位,依次为1到9,然后输出,这样效率是最高的。
    如果要代码最少,用Arrays.sort,但效率低。用正则效率低,且没有用Arrays.sort更精简。
      

  19.   

    public static void printInOrder(int[] array) {
    class NumberGroup {
    private int id; private Vector<Integer> numbers; public NumberGroup(int id, int newNumber) {
    this.id = id;
    numbers = new Vector<Integer>();
    addNumber(newNumber);
    } public int getID() {
    return id;
    } public void addNumber(int newNumber) {
    boolean numberExist = false;
    int numNumbers = numbers.size();
    Integer number;
    for (int i = 0; i < numNumbers; i++) {
    number = numbers.elementAt(i);
    if (number.intValue() == newNumber) {
    numberExist = true;
    break;
    }
    }
    if (!numberExist) {
    numbers.add(newNumber);
    }
    } public String toString() {
    System.out.println("*************" + id + "*************");
    StringBuffer sb = new StringBuffer();
    int size = numbers.size();
    for (int i = 0; i < size; i++) {
    System.out.println(numbers.elementAt(i));
    sb.append(numbers.elementAt(i) + '\n');
    }
    sb.append(" ");
    return "";
    }
    }
    Vector<NumberGroup> numberGroups = new Vector<NumberGroup>();
    for (int i = 0; i < array.length; i++) { int copy = Math.abs(array[i]);
    // get the highest digit
    while (copy > 0) {
    if (copy > 0 && copy < 10) {
    break;
    }
    copy = copy / 10;
    }
    System.out.println("Matching ID :" + copy);
    boolean groupExist = false;
    NumberGroup numberGroup = null;
    int groupSize = numberGroups.size();
    for (int j = 0; j < groupSize; j++) {
    numberGroup = numberGroups.elementAt(j);
    if (numberGroup.getID() == copy) {
    groupExist = true;
    break;
    }
    }
    if (!groupExist) {
    numberGroups.add(new NumberGroup(copy, array[i]));
    } else {
    numberGroup.addNumber(array[i]);
    }
    } // print the number groups int groupSize = numberGroups.size();
    for (int i = 0; i < groupSize; i++) {
    System.out.println(numberGroups.elementAt(i));
    }
    }
      

  20.   

    很简单的呀String[] a = {"134","133","13","32","34","52","5531"};
    java.util.Arrays.sort(a);
    char c = 0;
    for(int x=0;x<a.length;x++) {
      if(c!=a[x].charAt(0)&& c!=0)
         System.out.println();
      System.out.println(a[x]);
      c=a[x].charAt(0);
    }
      

  21.   

    private void print( String[] strs) {   
            Arrays.sort(strs);
            char firstNum = 0;
            for (String a : strs) {           
                if (a.charAt(0)==firstNum) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                    firstNum=a.charAt(0);
                }
                 System.out.print(a);
            }
        }
      

  22.   

    public static void main(String [] args)
    {
       String [] arrays = new String[]{"23","2","3","234","365","564","12","13","34", "35"};
       int i=0;
       while(true)
       {
          for(int j=0,len=arrays.length;j<len;j++)
          {
             String tmp = arrays[j];
             if(tmp.subString(0,1).equals(i.toString()))
             {            
                System.out.println(tmp);            
             }                 
          }
          i++;
          System.out.println("");
          if(i==9)
          {
             break;
          }   }
    }
      

  23.   

    最简单应该是定义一2维数组。array[n][9];分别以1至9作为列,将等排序的数组内的数填充到此2维数组,最后输出此2维数组。
      

  24.   

    public class Main {
    public static void main(String[] args) {
    Integer[] array = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35};
    int[][] test=new int[6][array.length];
    for(int i=0;i<array.length;i++) {
    //这行把第一个字符取出来转成STRING类型,直接用CHAR类型在下面会报错~-~
    String temp=String.valueOf(array[i].toString().charAt(0));
    //这行做赋值
    test[Integer.parseInt(temp)][i]=array[i];
    }
    for(int i=0;i<test.length;i++) {
    for(int j=0;j<array.length;j++) {
    if(test[i][j]==0) continue;
    else System.out.println(test[i][j]);
    }
    System.out.println();
    }
    }
    }代码有问题!
      

  25.   

    大家看看  这是 我写的  感觉 应该是最终解决方案(不用排序既可)import java.util.Random;public class DataDic {
    public static void main(String[] args) {
    String[] aryStr = new String[100000];
    java.util.Random rnd = new Random();
    for (int x = 0; x < aryStr.length; x++)
    aryStr[x] = String.valueOf(rnd.nextInt(100));
    DataDic d = new DataDic();
    long sl = System.currentTimeMillis();
    // d.sortA(aryStr); //方法一
    d.sortB(aryStr); // 方法二 最终解决方案
    long el = System.currentTimeMillis();
    System.out.println("\n总耗时:" + (el - sl) + "ms");
    } public void sortA(String[] aryStr) {
    java.util.Arrays.sort(aryStr);
    char c = 0;
    for (int x = 0; x < aryStr.length; x++) {
    char ctmp = aryStr[x].charAt(0);
    if (c != ctmp && c != 0)
    System.out.println();
    System.out.println(aryStr[x]);
    c = ctmp;
    }
    } public void sortB(String[] aryStr) {
    String indexStr = "0123456789";
    boolean isTrue = false;
    for (int x = 0; x < indexStr.length(); x++) {
    char isTmp = indexStr.charAt(x);
    for (int y = 0; y < aryStr.length; y++) {
    if (aryStr[y].charAt(0) == isTmp) {
    System.out.println(aryStr[y]);
    isTrue = true;
    }
    }
    if (isTrue) {
    System.out.println();
    isTrue = false;
    }
    }
    }
    }
      

  26.   


    # include <stdin.h>
    # define N=10;void main(){
       int a[N]=(23,2,3,234,365,564,12,13,34,35);
       int b[N]; //首数字
       int i=0;
       int j=0;  for(i=0;i<N;i++){
         b[i]=a[i];
         for(j=0;b[i]>10;j++){
             b[i]=b[i]/10;
         }
      }
      for(i=1;i<=9;i++){
        for (j=0;j<N;j++){
            if(b[j]=i) printf("d%/n",b[j]);
        }
       print(" /n");
      }
    }
      

  27.   

    public static void sortNumber(int[] src){
      Map<Integer,TreeSet<Integer>> map = new TreeMap<Integer,TreeSet<Integer>>();
      for (int number : src){
        int first = getFirstNumber(number);
        TreeSet<Integer> list;
        if (map.containsKey(first)){
          list = map.get(first);
        }else{
          list = new TreeSet<Integer>();
        }
        list.add(number);
        map.put(first, list);
      }
      System.out.println();
      for (Entry<Integer, TreeSet<Integer>> entry : map.entrySet()){
        TreeSet<Integer> list = entry.getValue();
        for (Integer number : list){
          System.out.print(number);
          System.out.print(" ");
        }
        System.out.println();
      }
    }

    public static int getFirstNumber(int num){
      int tmp = num;
      while(tmp >= 10){
        tmp /= 10;
      }
      return tmp;
    }测试:
    int[] src = {21,222,31,234,123,653,702,1,56,905,4534,1432};
    sortNumber(src);输出:1 123 1432 
    21 222 234 
    31 
    4534 
    56 
    653 
    702 
    905
      

  28.   

    我测试了楼上的帖子  效率都不这么滴  数据量小的情况下看不出来  
    我的测试环境是 
    String[] aryStr = new String[100000];
    java.util.Random rnd = new Random();
       for (int x = 0; x < aryStr.length; x++)
          aryStr[x] = String.valueOf(rnd.nextInt(1000));
    使用aryStr数组作为参数  我的程序仅用43毫秒(在不打印输入的情况下)如果进行排序,仅仅排序就要耗费至少100ms的时间
          public void sortB(String[] aryStr) {
    String indexStr = "0123456789";
    boolean isTrue = false;
    for (int x = 0; x < indexStr.length(); x++) {
    char isTmp = indexStr.charAt(x);
    for (int y = 0; y < aryStr.length; y++) {
    if (aryStr[y]!=null && aryStr[y].charAt(0) == isTmp) {
    System.out.println(aryStr[y]);
    isTrue = true;
    aryStr[y]=null;
    }
    }
    if (isTrue) {
    System.out.println();
    isTrue = false;
    }
    }
    }
      

  29.   

    String temp=String.valueOf(array[i].toString().charAt(0));应该改写成了
        String temp=String.valueOf(array[i]);
        temp = String.valueOf(temp.charAt(0));
      

  30.   

    [code]
    public class Test3 {
        private static final int[] tarr = {23, 2 ,3 ,234 ,365 ,564, 12, 13, 34 ,35};
        private static String[] arr = intConvertStr(tarr);
        private static char[] c = {'1','2','3','4','5','6','7','8','9'};    public static void main(String[] args){        long b = System.currentTimeMillis();        for (int j = 1; j < 10; j++) {
                for (int i = 0; i < arr.length; i++) {
                    if (arr[i].charAt(0) == c[j - 1]) {
                        System.out.println(arr[i]);
                    }
                }
                System.out.println("\r\n");
            }        System.out.println("time is:" + (System.currentTimeMillis() - b));
        }    public static String[] intConvertStr(int[] arr){
            String[] result = new String[arr.length];
            for (int i = 0; i < arr.length; i++){
                result[i] = String.valueOf(arr[i]);
            }
            return result;
        }
    }
    [/code]
      

  31.   

    放到Vector中,字符串形势,然后利用自带的排序功能 ,应该比较快
      

  32.   

    都是垃圾方法  看下我的方法  不用排序 
    indexStr 定义输出顺序isTrue 控制输出空格public void sortB(String[] aryStr) {
    String indexStr = "0123456789";
    boolean isTrue = false;
    for (int x = 0; x < indexStr.length(); x++) {
    char isTmp = indexStr.charAt(x);
    for (int y = 0; y < aryStr.length; y++) {
    if (aryStr[y].charAt(0) == isTmp) {
    System.out.println(aryStr[y]);
    isTrue = true;
    }
    }
    if (isTrue) {
    System.out.println();
    isTrue = false;
    }
    }
    }
      

  33.   

    凡是使用集合者 一律pass掉 测试完大数量的运行效率后说话
      

  34.   

    wt_adam(Adam)  的代码有bug 如果数据为 23,23,34,66的情况下 会连续输出 2个空格
      

  35.   

    看他要空间还是时间了
    反正就是判断头
    除10。。
    建10个LIST
    分别存
    题目没叫排序吧。。
    就顺序输出各数组就行了
      

  36.   

    public class TestArray4 {
    public static void main(String[] args) {
    String[] str1 = {"12",  "13", "130", "1546", "12345", "23", "234", "25", "356", "32", "365 "};
    for(int i=1;i<10;i++){
    System.out.println(i+":");
    for(int j=0;j<str1.length;j++){
    if(str1[j].startsWith(String.valueOf(i)))
    System.out.println(str1[j]);
    }
    }
    }}
      

  37.   

    int[] a = { 23, 2, 3, 234, 365, 564, 12, 13, 34, 35 };
    for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < a.length; j++) {
    if (String.valueOf(a[j]).startsWith(String.valueOf(i))) {
    System.out.println(a[j]);
    }
    }
    System.out.print("\n");
    }
      

  38.   

    我觉得是考察对String的应用...
      

  39.   

    import java.util.*;
    public class Order
    {
    public static void main(String args[])
    {
    Integer[] num = {23,2,3,234,365,564,12,13,34,35,49,62,60,78};
    //HashMap<Character,String> hm = new HashMap<Character,String>();
    HashMap<Integer,String> hm = new HashMap<Integer,String>();
    for(int i = 0;i<num.length;i++)
    {
    String s = num[i].toString();
    //char c  = s.charAt(0);
    Integer c  = (int)s.charAt(0) - 48;
                 if(hm.containsKey(c))
                    hm.put(c,hm.get(c)+" "+s);
                 else
                    hm.put(c,s);
    }

    //Set<Character> s = hm.keySet();
    //Iterator<Character> iterator = s.iterator();
    Set<Integer> s = hm.keySet();
    Iterator<Integer> iterator = s.iterator();
    while(iterator.hasNext())
    {
    System.out.println(hm.get(iterator.next()));
    }
    }
    }
      

  40.   

    import java.util.*;
    public class test {
    public static void main(String[] args) {
                       String []str =                                                                                    {"23","2", "3", "234", "365", "564", "12", "13", "34", "35"};
         Arrays.sort(str);
    System.out.println(str[0]);
    for(int i = 1; i < str.length; i++) {
    if(str[i-1].charAt(0) != str[i].charAt(0))
    System.out.println();
    System.out.println(str[i]);
    }
    }
    }
      

  41.   

    修改以后
    //datadis.c
    # include <stdio.h>void main(){
    int a[10]={23,2,3,234,365,564,12,13,34,35};
       int b[10]; //首数字
       int i=0;
       int j=0;  for(i=0;i<10;i++){
         b[i]=a[i];
         for(j=0;b[i]>10;j++){
             b[i]=b[i]/10;
         }
      }
      for(i=1;i<=9;i++){
        for (j=0;j<10;j++){
            if(b[j]==i) printf("%d\n",a[j]);
        }
       printf(" \n");
      }
    }用java 重写
    //Datadis.java
    import java.util.*;public class Datadis{
      public static void main(String[] args){
         int[] a={23,2,3,234,365,564,12,13,34,35};
          int[] b=new int[10]; //首数字
          int i=0;
          int j=0;
          int N=10;     for(i=0;i<N;i++){
            b[i]=a[i];
            for(j=0;b[i]>10;j++){
               b[i]/=10;
            }
        }
        for(i=1;i<=9;i++){
            for (j=0;j<N;j++){
              if(b[j]==i)
               System.out.println(a[j]);
            }
           System.out.println(" ");
        }
      }
    }
      

  42.   

    public class Testjava {    public static void main(String[] args) {
            int[] testArray = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35};
            String[] result={"","","","","","","","",""};
            int testsize=testArray.length;
            for(int i=0;i<testsize;i++)
            {
                result[Integer.parseInt((testArray[i]+"").substring(0,1))]+=testArray[i]+"\n";
            }
            for(int j=0;j<9;j++)
            {
                if(result[j]!="")
                {  
                    System.out.println();
                    System.out.print(result[j]+"");
                }
            }
        }
    }
      

  43.   

    不好意思,改了一点,,效率不错..public class Testjava {    public static void main(String[] args) {
           // int[] testArray = {23,2,3, 234, 365 ,564 ,12 ,13 ,34 ,35};
            
            int[] testArray = new int[1000];
            java.util.Random rnd = new Random();
               for (int x = 0; x < testArray.length; x++)
                   testArray[x] = rnd.nextInt(1000);
            
            String[] result={"","","","","","","","","",""};
            int testsize=testArray.length;
            for(int i=0;i<testsize;i++)
            {
                result[Integer.parseInt((testArray[i]+"").substring(0,1))]+=testArray[i]+"\n";
            }
            for(int j=0;j<10;j++)
            {
                if(result[j]!="")
                {  
                    System.out.println();
                    System.out.print(result[j]+"");
                }
            }
        }
    }
      

  44.   

    public static void main(String[] args) { int[] testArray = { 23, 2, 3, 234, 365, 564, 12, 13, 34, 35 };
    String[] str = new String[testArray.length]; for (int i = 0; i < str.length; i++) {
    str[i] = testArray[i] + "";
    } for (int i = 1; i <= 9; i++) {
    String temp = null;
    for (int j = 0; j < str.length; j++) {
    String s = str[j];
    String t = Integer.toString(i);
    if (s.charAt(0) == t.charAt(0)) {
    temp = s;
    System.out.println(s);
    }
    }
    if (temp != null) {
    System.out.println();
    }
    }

    }
      

  45.   

    假设数据存储在一个数组中,可以判断比较每个数组项第一个字符,然后按ascii码排序即可
      

  46.   

    这个思路可以吗:定义9个数组array1...array9遍历你那个存放N个数的数组,每遍历到一个数,就根据它的首位数,放到上面定义的对应数组中遍历完后,打印array1至array9中的每个数.
      

  47.   

    最喜欢 sunnykun(阿包) 的
      

  48.   

    小弟初次答题,请指教:)/**
     * 钱某人做:)
     */
    package sort;
    import java.util.ArrayList;public class SortLogic {
    ArrayList<NumDef> list = new ArrayList<NumDef>();

    //获取一个数的第一位数字
    public int getFirst(int num){
    while(num >= 10){
    num = num / 10;
    }
    return num;
    }

    /**
     * 将自定义的对象数组初始化,然后将其逐个添家到list中;
     * @param arr
     */
    public void NumDefInit(int[] arr){
    NumDef[] numDef = new NumDef[arr.length];
    for(int i = 0;i < arr.length;i++){
    numDef[i] = new NumDef();
    numDef[i].value = arr[i];
    numDef[i].firstNum = getFirst(arr[i]);
    list.add(numDef[i]);
    }

    }

        /**
         * 用循环找出第一位分别为1,2,3的数字将其打印出来后从list中删除
         * 然后进行下下一次循环,直到list为空。
         *
         */
    public void out(){
    while(list.size() != 0){
    int i = 0;
    while(((NumDef)list.get(i)).firstNum != 1){
    i++;
    }
    System.out.print(((NumDef)list.get(i)).value + "  ");
    list.remove(i);

    i = 0;
    while(((NumDef)list.get(i)).firstNum != 2){
    i++;
    }
    System.out.print(((NumDef)list.get(i)).value + "  ");
    list.remove(i);

    i = 0;
    while(((NumDef)list.get(i)).firstNum != 3){
    i++;
    }
    System.out.print(((NumDef)list.get(i)).value + "  ");
    list.remove(i);
    System.out.println();

    }

    }
    // 定义一个类,用来存放各个数值和每个数值的第一位数字
    private class NumDef{
    int value;
    int firstNum;

    }

    public static void main(String[] args) {
    int[] array = {12,35,24,11,345,246,333,211,123};
    SortLogic sortLogic = new SortLogic();
    sortLogic.NumDefInit(array);
    sortLogic.out(); }}
      

  49.   

    唉~  想不到 CSDN上 众人水平也不过如此
      

  50.   

    import java.util.Arrays;public class ArraysTest
    {
      
      
      public static void main(String[] args)
      {
        int[] a={23 ,2 ,3 ,234,365 ,564, 12 ,13 ,34 ,35};
        Arrays.sort(a);//排序
        for(int i=1;i<9;i++)//1-9作比较用
        {
          for(int j=0;j<a.length;j++)//提取第一位并与i比较相等好输出
          {
            int b=a[j];        
            while(b>10)
              b=b/10;
            if(b==i)
            System.out.println(a[j]);
          }
           
          System.out.println();//输出空行
        }    
        
      }
    }
      

  51.   

    acefr() 我靠你两个星星怎么骗来的,人家是N个数啊,还charAt()
      

  52.   

    算下来leshengdui() 的方法最好
    纯数字运算,效率最高。对于各种情况的适用性都不错