Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.util.Scanner;
  2. //================================================================
  3. public class ArrayIrreg {
  4. //----------------------------------------------------------------
  5. private static Scanner Keyboard = new Scanner(System.in);
  6.  
  7. public static void main(String[] args) {
  8. //----------------------------------------------------------------
  9. char group, rLetter;
  10.  
  11. int num = 10; // for test
  12. int rows = 10;
  13. int columns = 8;
  14.  
  15. // creating 2d array
  16.  
  17.  
  18. System.out.print("Please enter number of rows : ");
  19. rows = Keyboard.nextInt();
  20.  
  21. while (rows < 0 || rows >= 10) {
  22. System.out.print("ERROR:Out of range, try again : ");
  23. rows = Keyboard.nextInt();
  24. }
  25.  
  26. double[][] figures = new double[rows + 1][num];
  27.  
  28. for(int t = 0; t < rows; t++) {
  29. rLetter = (char)((t)+(int)'A');
  30. System.out.print("Please enter number of positions in row " + rLetter + " : ");
  31. columns = Keyboard.nextInt();
  32.  
  33. while(columns < 0 || columns >= 8) {
  34. System.out.print("ERROR:Out of range, try again : ");
  35. columns = Keyboard.nextInt();
  36. }
  37.  
  38. for(int j = 0; j <= columns; j++) {
  39. figures[j] = new double[j] ;
  40. }
  41.  
  42. }
  43.  
  44. // filling the array
  45. for(int row = 0; row < figures.length; ++row) {
  46. for(int col = 0; col < figures[row].length; ++col) {
  47. figures[row][col] = 0.0;
  48. }
  49. }
  50.  
  51. // printing the array
  52. for(int row = 0; row < figures.length; ++row) {
  53. // printing data row
  54. group = (char)((row)+(int)'A');
  55. System.out.print(group + " : ");
  56.  
  57. for(int col = 0; col < figures[row].length; ++col) {
  58. System.out.print(figures[row][col] + " ");
  59. System.out.print(" ");
  60. }
  61.  
  62. System.out.println();
  63. }
  64.  
  65. // printing final border
  66. for(int col = 0; col < figures[0].length; ++col) {
  67. System.out.print("-+");
  68. }
  69.  
  70. System.out.println(" ");
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement