This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| const i = 12; | |
| print('fibonacci($i) = ${fibonacci(i)}'); | |
| } | |
| /// Computes the nth Fibonacci number. | |
| int fibonacci(int n) { | |
| return n < 2 ? n : (fibonacci(n - 1) + fibonacci(n - 2)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| var i = 12; | |
| System.out.println("fibonacci(" + i + ") = " + fibonacci(i)); | |
| } | |
| /** | |
| * n番目のフィボナッチ数を計算する | |
| * | |
| * @param n 数列の項番 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class BubbleSort { | |
| public static void main(String[] args) { | |
| int[] scores = {90, 70, 50, 80, 100, 200, 300}; | |
| // 最適化していないバブルソーティングアルゴリズムを使った総比較回数の計算を行う。計算式は、(n-1)(n-1+1)/2 | |
| int n = scores.length; | |
| int totalComparisons = (n - 1) * (n - 1 + 1) / 2; | |
| System.out.println("総比較回数: " + totalComparisons); // 総比較回数: 21 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.ThreadLocalRandom; | |
| public class Utils { | |
| /** | |
| * 1から9までのランダムな整数を生成して返します。(スレッドセーフな乱数生成) | |
| * | |
| * @return 1から9までのランダムな整数 | |
| */ | |
| private int getRandomInt() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // クラスフィールドとインスタンスフィールドの実験目的なため、コンストラクタやアクセサメソッドなどは用意しない. | |
| public class Student { | |
| // クラスフィールド | |
| private static String schoolName; | |
| // インスタンスフィールド | |
| private String name; | |
| private int age; | |
| public static void main(String[] args) { | |
| System.out.println("==========Tanaka==========="); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class VolatileSample { | |
| private static volatile int count = 0; // メインメモリの変数に対して読み書きする | |
| // private static int count = 0; // 各スレッドの対応するキャッシュした変数に対して読み書きする | |
| public static void main(String[] args) { | |
| new MultiThread1().start(); | |
| new MultiThread2().start(); | |
| } | |
| // Thread-0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.io.ObjectInputStream; | |
| import java.io.ObjectOutputStream; | |
| import java.io.Serializable; | |
| class TransientSample01 { | |
| public static void main(String[] args) { | |
| var person = new Person("Tanaka", 20, "Tokyo", "09012345678"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static class Person { | |
| public int age; | |
| } | |
| public static void main(String[] args) { | |
| System.out.println("参照型 配列の実験-START"); | |
| int[] arrayInt = {10, 20, 30}; // インスタンス生成 | |
| foo(arrayInt); | |
| System.out.println(arrayInt[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxx; // TODO 自分のパッケージ名に変更する | |
| import androidx.appcompat.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.widget.ArrayAdapter; | |
| import android.widget.Spinner; | |
| public class MainActivity extends AppCompatActivity { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package xxxx; // TODO パッケージ名は自分の環境に合わせてください | |
| import android.annotation.SuppressLint; | |
| import android.content.Context; | |
| import android.util.AttributeSet; | |
| import android.util.Log; | |
| import android.view.MotionEvent; | |
| import android.view.View; | |
| import android.view.ViewTreeObserver; |
NewerOlder