第八屆藍橋杯B組java第四題

來源:互聯網
上載者:User

標籤:stat   bsp   地方   整數   blog   注意   題目   print   pre   

標題:取數位


求1個整數的第k位元字有很多種方法。
以下的方法就是一種。


對於題目中的測試資料,應該列印5。

請仔細分析源碼,並補充劃線部分所缺少的代碼。

注意:只提交缺失的代碼,不要填寫任何已有內容或說明性的文字。。

public class Test4 {    static int len(int x) {        if (x < 10)            return 1;        return len(x / 10) + 1;    }    // 取x的第k位元字    static int f(int x, int k) {        if (len(x) - k == 0)            return x % 10;        return f(x/10, k );// 填空//明顯 這個地方通過判斷長度是否符合 來返回那個位元上的值    }    public static void main(String[] args) {        int x = 23513;        // System.out.println(len(x));        System.out.println(f(x, 3));    }}

 

第八屆藍橋杯B組java第四題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.