浦發(fā)機試題目

超越姐姐鎮(zhèn)樓,祝大家機試遇到你會的問題。


祝我成功上岸

1.大小寫轉(zhuǎn)換

public static String upLowCase(String str){
        return str.toLowerCase();
    }
    
public static String lowUpCase(String str){
        return str.toUpperCase();
    }

2.1990年到2010年的閏年

    public static boolean isleapyear(int year){
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) ;
    }

3.判斷一個數(shù)是否是質(zhì)數(shù)

public static boolean isprimenum(int num){
        if(num <= 3)
            return num > 1;
        for(int i = 2 ; i < num ; i++){
            if( num%i == 0)
                return false;
        }
        return true;
    }

4.輸入一個數(shù)字要求輸出該數(shù)字各個位上偶數(shù)的和,如輸入5584,輸出12

public static int sum(String str){
        int sum = 0 ;
        for(int i = 0 ; i < str.length() ; i ++){
            int num = Integer.parseInt(str.charAt(i)+"");
            if( num % 2 == 0)
                sum += num;
        }
        return sum;
    }
    public static void main(String args[]){
        Scanner scann = new Scanner(System.in);
        String str = scann.nextLine();
        scann.close();
        System.out.println(sum(str));
        
    }

5.輸入一組數(shù)N和數(shù)字b ,求出該組數(shù)字中能被b 整除的個數(shù)。如輸入1 2 3 4 5 6和 2,結(jié)果輸出為3

    public static int div(String str,int b){
        int count = 0 ;
        String [] strArr = str.split(" ");
        for(int i = 0 ; i < strArr.length ; i++ ){
            int num = Integer.parseInt(strArr[i]);
            if( num % b == 0)
                count++;
        }
        return count;
    }
    public static void main(String args[]){
        Scanner scann = new Scanner(System.in);
        String str = scann.nextLine();
        int b = scann.nextInt();
        scann.close();
        System.out.println(div(str,b));
        
    }

6.求N階樓梯共有多少種上樓方式,每次只能上1個或2個臺階

    public static int palouti(int num){
        if(num == 0)
            return 0;
        if( num == 1)
            return 1;
        if( num == 2)
            return 2;
        return palouti(num-1)+palouti(num-2);
    }

7.字符串反轉(zhuǎn)

    public static String reverse(String str){
        StringBuffer buffer = new StringBuffer(str);
        return buffer.reverse().toString();
    }
    

8.非完全平方數(shù)的判斷

    public static boolean isSqrtNum(int num){
        int i = 1 ;
        while(num > 0){
            num -= i;
            i += 2;
        }
        return num == 0 ;
    }
    
    public static void main(String args[]){
        Scanner scann = new Scanner(System.in);
        int num = scann.nextInt();
        System.out.println(isSqrtNum(num));
        
    }

9.輸入一段話輸出字的個數(shù)

10.猴子吃桃子問題
猴子第一天摘下N個桃子,當時就吃了一半,還不過癮,就又吃了一個。第二天又將剩下的桃子吃掉一半,又多吃了一個。以后每天都吃前一天剩下的一半零一個。到第10天在想吃的時候就剩一個桃子了,求第一天共摘下來多少個桃子?

    public static int eatpeaches(int days){
        int sum = 1;
        for(int i = days ; i > 1 ; i-- ){
            sum = (sum+1)*2;
        }
        return sum;
    }

11.給出一個字符串,由不同的單詞用空格隔開的,然后呢,把這些單詞的首字母取出并大寫輸出
如輸入:hello world,輸出:HW,不過代碼都是要求你實現(xiàn)多行輸入的
輸出的,輸入0則停止輸入。

    public static String optionup(String str){
        String [] strarr = str.split(" ");
        String s = "";
        for(int i = 0 ; i < strarr.length ; i++){
            s += (strarr[i].charAt(0)+"").toUpperCase();
        }
        return s;
    }
    public static void main(String args[]){
    
        System.out.println(optionup("hello World!"));
        
    }

12.1加2/3加3/5加4/7.......輸出結(jié)果。(加號打不出來啊)
//這里注意一下,什么進位方式

    public static double sumdb(int num){
        double db = 0.0d;
        for(int i = 1 ; i <= num ; i++){
            db += i / ((2.0 * i) - 1.0);
        }
        return db;
    }
    public static void main(String args[]){
    
        System.out.println(sumdb(2));
        
    }

13.把字符串中的字符a和A換成c輸出

    public static String replaceAC(String str){
        str = str.replaceAll("a","c");
        str = str.replaceAll("A","c");
        return str;
    }

14.給你年月日,求出是這年的第幾天

    public static int getdays(int year,int month,int day){
        int days = 0;
        
        switch(month - 1){
            case 12: days += 31;
            case 11: days += 30;
            case 10: days += 31;
            case 9: days += 30;
            case 8: days += 31;
            case 7: days += 31;
            case 6: days += 30;
            case 5: days += 31;
            case 4: days += 30;
            case 3: days += 31;
            case 2: days += 28;
            case 1: days += 31;
        }
        
        days += day;
        
        if( month > 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 ==0) ))
            days ++;
        
        return days;
    }
    
    public static void main(String args[]){
    
        System.out.println(getdays(2019,2,1));
        
    }

15.小球從100米下落,每次回彈一半距離,第幾次落地后的總距離。

    public static double summiles(int count){
        double all = 100.0d;
        for( ; count > 0 ; count --){
            all /= 2.0;
        }
        return all;
    }
    public static void main(String args[]){
    
        System.out.println(summiles(1));
        
    }

16.從求組中找出唯一出現(xiàn)一次得數(shù)。

    public static int unique(int [] numarr){
        for(int i = 0 ; i < numarr.length ; i++){
            int count = 0;
            for(int j = 0 ; j < numarr.length ; j ++){
                if(numarr[i] == numarr[j])
                    count ++;
            }
            if(count == 1){
                return numarr[i];
            }
        }
        return -1;
    }
    public static void main(String args[]){
    
        System.out.println(unique(new int[]{1,1,1,2,3,3}));
        
    }

17.:A,B兩個字符串,求在第一個字符串出現(xiàn),第二個字符串中未出現(xiàn)的,重復(fù)只取第一次出現(xiàn),輸出字符串。

    public static String uniqueABstr(String stra,String strb){
        String newstr = "";
        for(int i = 0 ; i < stra.length() ; i ++){
            String s = stra.charAt(i) +"";
            if(!strb.contains(s))
                newstr += s;
        }
        return newstr;
    }
    public static void main(String args[]){
    
        System.out.println(uniqueABstr("123","2"));
        
    }

18.加密解密,就是給你由大寫字母組成的字符串,求出原來的字符串,加密 。方式很簡單就是字符串后移五位,比如原來是A加密后是F,其余數(shù)字等標點符號原樣輸出.

凱撒密碼 mod

public static String kaisacode(String str){
        String newstr = "";
        for(int i = 0 ; i < str.length() ; i ++){
            char ch = str.charAt(i);
            
            if( ch >= 'a' && ch <= 'z')
                newstr +=  (char)(( ch - 'a' + 5 ) % 26 + 'a'); 
// 加密 +
            else if( ch >= 'A' && ch <= 'Z')
                newstr +=  (char)(( ch - 'A' + 5 ) % 26 + 'A'); 
            else
                newstr += ch;
        }
        return newstr;
    }
    
    public static void main(String args[]){
    
        System.out.println(kaisacode("A"));
        
    }

19.輸入abc d 輸出abc d,就是去掉一個字符串最后的空格

    public static String trimkongge(String str){
        int i = str.length() - 1;
        for(; i > 0 ; i --){
            if(str.charAt(i) != ' ')
                break;
        }
        return str.substring(0,i+1);
    }

20.喝飲料問題,一塊錢一瓶飲料,兩個空瓶子換一瓶飲料
求4塊錢能和多少飲料

    public static int heyinliao(int num){
        int money = num;
        int ping = 0;
        int kongping = 0;
        while(money > 0){
            money --;
            ping ++;
            kongping ++;
            if(kongping == 2){
                ping ++;
                kongping = 0;
                kongping ++;
            }
        }
        if(kongping == 2)
            ping++;
        return ping;
    }

21階乘求和

    public static int jiecheng(int num){
        if( num == 1)
            return 1;
        return jiecheng(num - 1) * num;
    }
    
    public static void main(String args[]){ 
        int sum = 0;
        int num = 2;
        for(int i = 1 ; i <= num ; i ++){
            sum += jiecheng(i);
        }
        System.out.println(sum);
        
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在C語言中,五種基本數(shù)據(jù)類型存儲空間長度的排列順序是: A)char B)char=int<=float C)ch...
    夏天再來閱讀 4,061評論 0 2
  • 1.把二元查找樹轉(zhuǎn)變成排序的雙向鏈表 題目: 輸入一棵二元查找樹,將該二元查找樹轉(zhuǎn)換成一個排序的雙向鏈表。 要求不...
    曲終人散Li閱讀 3,505評論 0 19
  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,723評論 0 5
  • 1. 找出數(shù)組中重復(fù)的數(shù)字 題目:在一個長度為n的數(shù)組里的所有數(shù)字都在0到n-1的范圍內(nèi)。數(shù)組中某些數(shù)字是重復(fù)的,...
    BookThief閱讀 2,016評論 0 2
  • 說明: 本文中出現(xiàn)的所有算法題皆來自牛客網(wǎng)-劍指Offer在線編程題,在此只是作為轉(zhuǎn)載和記錄,用于本人學習使用,不...
    秋意思寒閱讀 1,219評論 1 1

友情鏈接更多精彩內(nèi)容