Skip to content

Instantly share code, notes, and snippets.

@mizushou
Last active October 9, 2017 18:56
Show Gist options
  • Save mizushou/24e5d144f3950fda4a55c047c77e6d47 to your computer and use it in GitHub Desktop.
Save mizushou/24e5d144f3950fda4a55c047c77e6d47 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class ConvertToIntArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("配列のサイズを入力してください。");
int n = sc.nextInt();
int[] A = new int[n];
System.out.println("配列の要素を空白区切りで入力してください。");
for(int i=0; i<n; i++){
A[i] = sc.nextInt();
};
System.out.print("あなたが入力した配列は : [ ");
for(int i=0; i<A.length; i++){
System.out.print(A[i] + " ");
};
System.out.println("]");
}
}
@mizushou
Copy link
Author

mizushou commented Oct 9, 2017

標準入力(キーボード)で受け取った数値を整数型の配列にする

  • 標準入力で以下のように空白区切りで数値を入力。入力した数値を整数型の配列に変換。
  • input
    1 2 3 4 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment