Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //================================================================
- public class ArrayIrreg {
- //----------------------------------------------------------------
- private static Scanner Keyboard = new Scanner(System.in);
- public static void main(String[] args) {
- //----------------------------------------------------------------
- char group, rLetter;
- int num = 10; // for test
- int rows = 10;
- int columns = 8;
- // creating 2d array
- System.out.print("Please enter number of rows : ");
- rows = Keyboard.nextInt();
- while (rows < 0 || rows >= 10) {
- System.out.print("ERROR:Out of range, try again : ");
- rows = Keyboard.nextInt();
- }
- double[][] figures = new double[rows + 1][num];
- for(int t = 0; t < rows; t++) {
- rLetter = (char)((t)+(int)'A');
- System.out.print("Please enter number of positions in row " + rLetter + " : ");
- columns = Keyboard.nextInt();
- while(columns < 0 || columns >= 8) {
- System.out.print("ERROR:Out of range, try again : ");
- columns = Keyboard.nextInt();
- }
- for(int j = 0; j <= columns; j++) {
- figures[j] = new double[j] ;
- }
- }
- // filling the array
- for(int row = 0; row < figures.length; ++row) {
- for(int col = 0; col < figures[row].length; ++col) {
- figures[row][col] = 0.0;
- }
- }
- // printing the array
- for(int row = 0; row < figures.length; ++row) {
- // printing data row
- group = (char)((row)+(int)'A');
- System.out.print(group + " : ");
- for(int col = 0; col < figures[row].length; ++col) {
- System.out.print(figures[row][col] + " ");
- System.out.print(" ");
- }
- System.out.println();
- }
- // printing final border
- for(int col = 0; col < figures[0].length; ++col) {
- System.out.print("-+");
- }
- System.out.println(" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement