乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Java算法面試題

       ricosxf 2014-09-22

      下面是某些企業(yè)常見的算法面試試題,現(xiàn)總結如下,僅供學員參考與學習。

      1.比較兩個字符串如果不等返回True?
      答案: 
       

      Java代碼 復制代碼
      1. package com.test.kaoshi;   
      2.   
      3. public class StringDemo {   
      4.   
      5.     private static String a = "abc";   
      6.     private static String b = "abcg";   
      7.   
      8.     public static boolean equalString() {   
      9.         if (a.equals(b)) {   
      10.             return false;   
      11.         } else {   
      12.                
      13.             return true;   
      14.         }   
      15.     }   
      16.     public static void main(String[] args) {   
      17.         StringDemo  sd = new StringDemo();   
      18.         System.out.println("主要考察返回Boolean變量和字符串比較使用的方法?+sd.equalString());   
      19.     }   
      20. }  
      1. package com.test.kaoshi;  
      2.   
      3. public class StringDemo {  
      4.   
      5.     private static String a = "abc";  
      6.     private static String b = "abcg";  
      7.   
      8.     public static boolean equalString() {  
      9.         if (a.equals(b)) {  
      10.             return false;  
      11.         } else {  
      12.               
      13.             return true;  
      14.         }  
      15.     }  
      16.     public static void main(String[] args) {  
      17.         StringDemo  sd = new StringDemo();  
      18.         System.out.println("主要考察返回Boolean變量和字符串比較使用的方法?+sd.equalString());  
      19.     }  
      20. }  




      2.隨機產(chǎn)生20個字符并且排序?

      答案:
       

      Java代碼 復制代碼
      1. package com.test.kaoshi;   
      2.   
      3. import java.util.HashSet;   
      4. import java.util.Iterator;   
      5. import java.util.Random;   
      6. import java.util.Set;   
      7. import java.util.TreeSet;   
      8.   
      9. public class RadomDemo {   
      10. /**  
      11.  * 隨機產(chǎn)生20個字符串并且字符串不能重復 且進行排序  
      12.  * @param random  
      13.  * @param len  
      14.  * @return  
      15.  */  
      16.     public Set getChar(){   
      17.            
      18.         Set numberSet01 = new HashSet();   
      19.         Random rdm = new Random();   
      20.         char ch;   
      21.         while(numberSet01.size()<20){    
      22.            int rdGet = Math.abs(rdm.nextInt())%26+97;//產(chǎn)生97到122的隨機數(shù)a-z值   
      23.             ch=(char)rdGet;   
      24.             numberSet01.add(ch);   
      25.             //Set中是不能放進重復的值的,當它有20個時,就滿足你的條件了    
      26.         }    
      27.           return numberSet01;   
      28.         }   
      29.     public static void main(String[] args) {   
      30.         RadomDemo rd = new RadomDemo();   
      31.         Set numberSet01=rd.getChar();   
      32.            
      33.         Set numberSet = new TreeSet();    
      34.         numberSet.addAll(numberSet01);   
      35.         for(Iterator it=numberSet01.iterator();it.hasNext();){    
      36.             System.out.print(it.next());    
      37.             }    
      38.         System.out.println();   
      39.         for(Iterator it=numberSet.iterator();it.hasNext();){    
      40.             System.out.print(it.next());    
      41.             }    
      42.     }   
      43. }  
      1. package com.test.kaoshi;  
      2.   
      3. import java.util.HashSet;  
      4. import java.util.Iterator;  
      5. import java.util.Random;  
      6. import java.util.Set;  
      7. import java.util.TreeSet;  
      8.   
      9. public class RadomDemo {  
      10. /** 
      11.  * 隨機產(chǎn)生20個字符串并且字符串不能重復 且進行排序 
      12.  * @param random 
      13.  * @param len 
      14.  * @return 
      15.  */  
      16.     public Set getChar(){  
      17.           
      18.         Set numberSet01 = new HashSet();  
      19.         Random rdm = new Random();  
      20.         char ch;  
      21.         while(numberSet01.size()<20){   
      22.            int rdGet = Math.abs(rdm.nextInt())%26+97;//產(chǎn)生97到122的隨機數(shù)a-z值  
      23.             ch=(char)rdGet;  
      24.             numberSet01.add(ch);  
      25.             //Set中是不能放進重復的值的,當它有20個時,就滿足你的條件了   
      26.         }   
      27.           return numberSet01;  
      28.         }  
      29.     public static void main(String[] args) {  
      30.         RadomDemo rd = new RadomDemo();  
      31.         Set numberSet01=rd.getChar();  
      32.           
      33.         Set numberSet = new TreeSet();   
      34.         numberSet.addAll(numberSet01);  
      35.         for(Iterator it=numberSet01.iterator();it.hasNext();){   
      36.             System.out.print(it.next());   
      37.             }   
      38.         System.out.println();  
      39.         for(Iterator it=numberSet.iterator();it.hasNext();){   
      40.             System.out.print(it.next());   
      41.             }   
      42.     }  
      43. }  



      3.50個人圍成一圈數(shù)到三和三的倍數(shù)時出圈,問剩下的人是誰?在原來的位置是多少?


      答案:

       

      Java代碼 復制代碼
      1. package com.test.kaoshi;   
      2.   
      3. import java.util.Iterator;   
      4. import java.util.LinkedList;   
      5.   
      6. public class YouXi {   
      7.     public static int removeNM(int n, int m) {   
      8.         LinkedList ll = new LinkedList();   
      9.         for (int i = 0; i < n; i++)   
      10.             ll.add(new Integer(i + 1));   
      11.         int removed = -1;   
      12.         while (ll.size() > 1) {   
      13.             removed = (removed + m) % ll.size();   
      14.             ll.remove(removed--);   
      15.         }   
      16.         return ((Integer) ll.get(0)).intValue();   
      17.     }   
      18.   
      19.     public static void main(String[] args) {   
      20.         System.out.println(removeNM(503));   
      21.     }   
      22. }  

       

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多