久保友悟
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    WeAreJk T320008、石川恭雅 T320033、久保友悟 T320098、宮川裕貴 ********** 5.17 フィボナッチ数列の各項を、第 1 項から第 20 項まで求めて出力するプログラムを作成せよ。フィボナッチ数 列とは、 a1 =1,a2 =1,an=an−1+an−2 (n>2) で与えられる数列である。なお、このプログラムは配列を使わずに実現できるので、配列を使用しないこと。 ・プログラム public class p17 { public static void main(String[] args) { int m = 1, n = 1; System.out.println("a1=" + m); System.out.println("a2=" + n); for (int i = 3; i <= 20; i++) { System.out.printf("a%d=%d\n", i, m + n); int l = m + n; n = m; m = l; } } } ・出力結果 % java p17 a1=1 a2=1 a3=2 a4=3 a5=5 a6=8 a7=13 a8=21 a9=34 a10=55 a11=89 a12=144 a13=233 a14=377 a15=610 a16=987 a17=1597 a18=2584 a19=4181 a20=6765 ********** ********** 6.3 MethodSample2.java のような、static な isEven メソッドを利用するプログラムがある。isEven( )は整数が 偶数であるかどうかをチェックするメソッドである。以下の実行結果になるように isEven メソッドの定義を 追加せよ。 実行結果 2 は偶数です 4 は偶数です 6 は偶数です 8 は偶数です 10 は偶数です ・プログラム public class MethodSample2Ensyuu { static boolean isEven(int a) { if (a % 2 == 0) { return true; } else { return false; } } public static void main(String[] args) { int nums[] = {1,2,3,4,5,6,7,8,9,10}; for (int n:nums) { if(isEven(n)) System.out.println(n+"は偶数です。"); } } } ・出力結果 % java MethodSample2Ensyuu 2は偶数です。 4は偶数です。 6は偶数です。 8は偶数です。 ********** ********** 演習課題(6.6) MaxSample.java は、staticなmaximum ( メソッド を利用するプログラムである。 maximum ( は渡された 1 次元配列 の要素の最大値を求め、それを返すメソッドである。 MaxSample クラス 内で main ( メソッド が記述されているが、maximum(メソッドの定義は抜けている。 maximum ( メソッドの定義を 追加し、プログラムを完成せよ。 プログラム public class MaxSanple { public static int maxnum(int a[]){ int i,max; max = a[0]; for(i=0;i<a.length;i++){ if(max<a[i]){ max = a[i]; } } return max; } public static void main(String[] args) { int a[] = {10,20,50,15,5,40,30}; int b[] = {-10,-20,-50,-15,-5,-40,-35,-60}; System.out.println(maxnum(a)); System.out.println(maxnum(b)); } } 実行結果 50 -5 ********** ********** 演習課題(6.9) Block クラス は長方形の幅、高 さ や面積を現す 3 つフィールド x, y , area 及び 3つのメソッド を持っている。 void 型の setBlock( ) メソッドは、長方形の幅と高さを設定し、面積を計算し、 それ を area に代入する。 sameBlock( ) と sameArea( )メソッドは Block クラスオブジェクト を受け取って、長方形の比較を行う。sameBlock( ) は 長方形の次元 を比較し、一致したときに true 、そうでないときに false を返す。 sameArea( ) は長方形の面積を比較し、一致した場合、 true 、そうでないときは false を返す。 Block クラスの sameBlock( ) は記述されているが、 setBlock( ) 及び sameArea( ) の記述は抜けている。 setBlock( ) 及びsameArea( の定義を追加し、動作を確認せよ。 プログラム class Block{ int x, y; //長方形の幅と高さを格納するフィールド int area; //長方形の面積を格納するフィールド // ここで setBlock( )メソッドの定義を追加 void setBlock(int nx, int ny) { x = nx; y = ny; area = x*y; } boolean sameBlock(Block obj) { if( (obj.x == x) && (obj.y == y) )return true; else return false; //この文は次のように省略できる。 // return (obj.x == x) && (obj.y == y); } // ここで sameArea( )メソッドの定義を追加 boolean sameArea(Block obj) { return (obj.area == area); } } public class BlockSample { public static void main(String args[]){ Block obj1 = new Block( ); Block obj2 = new Block( ); obj1.setBlock(4,6); obj2.setBlock(8,3); System.out.println("obj1 は obj2 と一致する:" + obj1.sameBlock(obj2)); //obj1.sameBlock(obj2)は obj1 と obj2 のサイズを比べる //obj2.sameBlock(obj1)のように書いても良い System.out.println("obj1 は obj2 と同じ面積を持つ:" + obj1.sameArea(obj2)); //obj1.sameArea(obj2)は obj1 と obj2 の面積を比べる //obj2.sameArea(obj1) のように書いても良い } } 実行結果 $ javac BlockSample.java && java BlockSample obj1 は obj2 と一致する:false obj1 は obj2 と同じ面積を持つ:true ******** ********** 6.17 check(int a, int … n)メソッドを持つプログラムを作成する。check は、a の値が可変引数の合計値を上回るときに true、そうではないときに false を表示するメソッドである。 プログラム public class enshu6_17 { static boolean check(int a, int ... n){ int x = 0; for(int i: n){ x += i; } return a > x; } public static void main(String args[]) { System.out.println(check(10,1,1,1)); System.out.println(check(10,10,10,10)); } } 出力結果 $ javac enshu6_17.java && java enshu6_17 true false ********** 6.21 コマンドライン引数として利用者に任意の数の整数を入力させ、それらの和を出力するプログラムを作成せよ。( テストデータ1: 15 16 200 300 テストデータ 2: 2 3 50 40 5 10) プログラム public class enshu6_21 { public static void main(String args[]) { int ans = 0; for (String s : args) { int arg = Integer.parseInt(s); ans += arg; } System.out.println(ans); } } 出力結果 $ javac enshu6_21.java && java enshu6_21 15 16 200 300 531 $ javac enshu6_21.java && java enshu6_21 2 3 50 40 5 10 110 **********

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully