转载请注明出处:http://hi.baidu.com/jadmin/blog/item/88a2853ea2cae8f8838b1318.html
/**
* @(#)DelColOfMatrix.java
*
* @author JAdmin
* @version 1.00 2007/8/22
*
*/
import java.util.Scanner;
public class DelColOfMatrix
{
public static void main(String[] args)
{
int row, col;
Scanner sr = new Scanner(System.in);
System.out.println("请输入矩阵相关参数:");
System.out.print("row=");
row = sr.nextInt();
System.out.print("col=");
col = sr.nextInt();
int[][] array = new int[row][col];
System.out.println("输入矩阵各元素:");
for (int i = 0; i < array.length; i++)
for (int j = 0; j < array[0].length; j++)
array[i][j] = sr.nextInt();
System.out.println("============The Matrix is============");
display(array);
System.out.println("请输入要删除的矩阵列序号");
System.out.print("delColNum=");
int delColNum = sr.nextInt();
int[][] newarr = delCol(array, delColNum);
System.out
.println("============The Matrix after Delete is============");
display(newarr);
}
private static void display(int[][] arr)
{
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[0].length; j++)
System.out.print(arr[i][j] + " ");
System.out.println();
}
}
private static int[][] delCol(int[][] arr, int delColNum)
{
int[][] tmparr = new int[arr.length][(arr[0].length - 1)];
for (int i = 0; i < arr.length; i++)
{
for (int j = delColNum - 1; j < arr[0].length - 1; j++)
arr[i][j] = arr[i][j + 1];
for (int k = 0; k < tmparr[0].length; k++)
tmparr[i][k] = arr[i][k];
}
return tmparr;
}
}
posted on 2007-08-22 09:35
jadmin 阅读(79)
评论(0) 编辑 收藏