【251天】我愛刷題系列(10)

叨叨兩句

  1. 我發現我真是適合當程序員,連續奮戰這麼多天,居然沒以爲痛苦!奇了!

題23: 返回一個包含pi(參考Math.PI)的前n位數字的整數數組長度

題目描述

書寫一個類,類名爲Itheima;程序員

類中有一個方法,方法名makePi;數組

返回一個包含pi(參考Math.PI)的前n位數字的整數數組長度,n爲方法接收的參數。
例如:n爲3,則返回{3,1,4}。code

提示

方法調用 指望值
makePi(1) [3]
makePi(2) [3,1]
makePi(3) [3,1,4]
public class Itheima{
    
    public int[] makePi(int n){
    
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.PI * Math.pow(10,i)%10);
        }
        return arr;
    }
}
相關文章
相關標籤/搜索