Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package labamama;
- import java.util.Random;
- public class labamama {
- public static void main(String[] args) {
- int a[][],columns=0, count=0;
- a=create(4,5);
- init(a);
- putout(a);
- columns=negative(a);
- count=count(columns);
- a=change(a, columns, count);
- putout(a);
- }
- //выделение памяти
- static int [][] create(int sz1, int sz2) {
- int b[][] = new int [sz1][];
- int i;
- for(i=0; i<sz1; i++)
- b[i]= new int[sz2];
- return b;
- }
- //инициализация
- static void init(int [][] b) {
- Random obj = new Random();
- int i, j;
- for(i=0; i<b.length; i++)
- for(j=0; j<b[i].length; j++)
- b[i][j] = obj.nextInt() % 100;
- }
- static int negative(int [][] b) {
- int count=0, i, j, helper=0;
- for(j=b[0].length-1; j>=0; j--) {
- for(i=0; i<b.length; i++)
- if(b[i][j]<0)
- helper++;
- if(helper>0) {
- count+=j;
- count*=10;
- }
- helper=0;
- }
- return count/10;
- }
- static int count (int p) {
- int count=0;
- while(p!=0) {
- count++;
- p/=10;
- }
- return count;
- }
- //добавление строки в двумерный массив
- static int [][] change(int [][] b, int colmn, int count) {
- int[][] c = create(b.length, b[0].length - count);
- copy(b,c, colmn);
- return c;
- }
- //копирование
- static void copy(int [][]f, int[][]s, int jnum) {
- int i, j, p=0;
- for(j=0; j<f[0].length; j++) {
- if(j!=jnum%10) {
- for(i=0; i < f.length; i++) {
- s[i][p]=f[i][j];
- }
- p++;
- }
- if(j==jnum%10)
- jnum/=10;
- }
- }
- // вывод
- static void putout(int [][]b) {
- int i, j;
- for(i=0; i<b.length; i++) {
- for(j=0; j<b[i].length; j++)
- System.out.format("%,4d",b[i][j]);
- System.out.println();
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement