Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created December 21, 2016 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/3255f48aa359a5f4b19c13f9dd3dedf0 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/3255f48aa359a5f4b19c13f9dd3dedf0 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習6-18
import java.util.Scanner;
public class en06_18 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int[][] c;
// 行数を入力させる
System.out.print("行数を入力して下さい:");
int n = stdIn.nextInt();
c = new int[n][];
System.out.println();
System.out.println("各行の列数を入力して下さい。");
for (int i = 0; i < c.length; i++) {
System.out.printf("c[%d] =", i);
int t = stdIn.nextInt();
c[i] = new int[t];
}
System.out.println();
System.out.println("各要素数を入力して下さい。");
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[i].length; j++) {
System.out.printf("c[%d][%d] =", i, j);
c[i][j] = stdIn.nextInt();
}
System.out.println();
}
System.out.println();
System.out.println("結果を表示");
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[i].length; j++) {
System.out.printf("%3d ", c[i][j]);
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment