日期:2014-05-20  浏览次数:20763 次

面试题,没有做出来
public   class   Test1   {
        static   int   k=0;
; static   final   String[]   s={ "1 ", "2 ", "3 ", "4 ", "5 "};
        public   static   void   getOne(String   ret,int   pos){
                if(pos> =4){
                        System.out.println(ret);
                      k=k+1;
                        return;
                }
                for(int   i=0;i <s.length;i++){
                        ret+=s[i];
                        getOne(ret,   pos+1);
                        ret=ret.substring(0,   pos-1);
                }
        }
        public   static   void   main(String[]   args){
                String   num= " ";
                getOne(num,   1);
                System.out.println(k);
        }
}
如果我只得第五位   四位的不要   应该怎么弄呢?

------解决方案--------------------
if(ret.charAt(0)== '5 '){System.out.println(ret);}
------解决方案--------------------
if(ret> =10000){System.out.println(ret);}

------解决方案--------------------
for(int i=0;i <s.length;i++){
//加一句
if(i!=3)
ret+=s[i];
getOne(ret, pos+1);
ret=ret.substring(0, pos-1);
}

------解决方案--------------------
你先把题目描述好吧..
------解决方案--------------------
不明白什么意思
------解决方案--------------------
全排列吧,
最小与最大,只要每次选取最大的就是最大,每次选取最小的就是最小
------解决方案--------------------
import java.io.*;

public class Test{

public static void main(String[] args) throws Exception
{

FileWriter out = new FileWriter( "result.txt ");
int count = 0;
for(int i = 123;i <= 321;i++)
{
String s = new String(i + " , ");
if(s.indexOf( "4 ")> =0)
{
continue;
}
else if(s.indexOf( "5 ")> =0)
{
continue;
}
else if(s.indexOf( "6 ")> =0)
{
continue;
}
else if(s.indexOf( "7 ")> =0)
{
continue;
}
else if(s.indexOf( "8 ")> =0)
{
continue;
}
else if(s.indexOf( "9 ")> =0)
{
continue;
}
else if(s.indexOf( "0 ")> =0)