Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package labamama;
  2.  
  3. import java.util.Random;
  4.  
  5. public class labamama {
  6.  
  7. public static void main(String[] args) {
  8. int a[][],columns=0, count=0;
  9. a=create(4,5);
  10. init(a);
  11. putout(a);
  12. columns=negative(a);
  13. count=count(columns);
  14. a=change(a, columns, count);
  15. putout(a);
  16.  
  17. }
  18. //выделение памяти
  19. static int [][] create(int sz1, int sz2) {
  20. int b[][] = new int [sz1][];
  21. int i;
  22. for(i=0; i<sz1; i++)
  23. b[i]= new int[sz2];
  24. return b;
  25. }
  26. //инициализация
  27. static void init(int [][] b) {
  28. Random obj = new Random();
  29. int i, j;
  30. for(i=0; i<b.length; i++)
  31. for(j=0; j<b[i].length; j++)
  32. b[i][j] = obj.nextInt() % 100;
  33. }
  34. static int negative(int [][] b) {
  35. int count=0, i, j, helper=0;
  36. for(j=b[0].length-1; j>=0; j--) {
  37. for(i=0; i<b.length; i++)
  38. if(b[i][j]<0)
  39. helper++;
  40. if(helper>0) {
  41. count+=j;
  42. count*=10;
  43. }
  44. helper=0;
  45. }
  46. return count/10;
  47. }
  48. static int count (int p) {
  49. int count=0;
  50. while(p!=0) {
  51. count++;
  52. p/=10;
  53. }
  54. return count;
  55. }
  56. //добавление строки в двумерный массив
  57. static int [][] change(int [][] b, int colmn, int count) {
  58. int[][] c = create(b.length, b[0].length - count);
  59. copy(b,c, colmn);
  60. return c;
  61. }
  62. //копирование
  63. static void copy(int [][]f, int[][]s, int jnum) {
  64. int i, j, p=0;
  65. for(j=0; j<f[0].length; j++) {
  66. if(j!=jnum%10) {
  67. for(i=0; i < f.length; i++) {
  68. s[i][p]=f[i][j];
  69. }
  70. p++;
  71. }
  72. if(j==jnum%10)
  73. jnum/=10;
  74. }
  75.  
  76. }
  77. // вывод
  78. static void putout(int [][]b) {
  79. int i, j;
  80. for(i=0; i<b.length; i++) {
  81. for(j=0; j<b[i].length; j++)
  82. System.out.format("%,4d",b[i][j]);
  83. System.out.println();
  84.  
  85.  
  86. }
  87. System.out.println();
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement