输入一个数组,当数组的某一行存在0,那么这一列上所有的数都变成0。
1例如:
请输入数组行和列:
3 3
请输入数组:
1 2 3
1 0 2
4 5 6
输出数组
1 2 3
0 0 0
4 5 6
2例如:
请输入数组行和列:
4 4
请输入数组:
1 2 3 4
0 5 6 7
8 9 10 11
12 0 13 14
输出数组
1 2 3 4
0 0 0 0
8 9 10 11
0 0 0 0
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入数组行和列:");
/*String s = input.nextLine();
System.out.println(s);*/
/** int n = s.length(); char [] x=s.toCharArray(); int ans = 0; int[]
* index = new int[128]; // current index of character // try to extend
* the range [i, j] for (int j = 0, i = 0; j < n; j++) { i =
* Math.max(index[s.charAt(j)], i); ans = Math.max(ans, j - i+1 );
* index[s.charAt(j)] = j+1; } int length_1=0; for(int i=1; i<n;i++){
* for(int j=0;j<i;j++){ if(x[i]!=x[j]){ length_1++; } if(x[i]==x[j]){
*
* } } } System.out.println(ans);
*/
int x = input.nextInt();
int y = input.nextInt();
int[][] a = new int[x][y];
System.out.println("请输入数组:");
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
a[i][j] = input.nextInt();
}
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
if (a[i][j] == 0) {
for (int c = 0; c < y; c++) {
a[i][c] = 0;
}
}
}
}
System.out.println("输出数组");
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}