Created
December 21, 2016 13:11
-
-
Save mokomokohitsuzi/3255f48aa359a5f4b19c13f9dd3dedf0 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習6-18
This file contains 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.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