0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mainで定義した配列を関数に引数として渡して処理する

Posted at
public class Main{
    public static void main(String[] args) {
        // 配列 int[] array を定義
        int[] array = new int[]{9, 10, 0, 2, 87, 1000};

        for(int i = 0; i <= array.length - 2; i++) {
            if(array[j] < array[j - 1]) {
                int temp = array[j];
                array[j] = array[j - 1];
                array[j - 1] = temp;
            }
        }
        // 関数 result を呼び出し
        result(array);
    }

    // mainで定義した int[] array を引数として渡す
    public static void result(int[] array) {
        for(int i = 0; i <= array.length - 1; i++) {
            System.out.println(array[i]);
        }
    }
}

結果

0
2
9
10
87
1000
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?