「java建立矩阵」java建立矩阵,其初值为
今天给各位分享java建立矩阵的知识,其中也会对java建立矩阵,其初值为进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、JAVa编写程序,建立并输出一个10*10的矩阵怎么做
- 2、(JAVA)建立一个m行n列的矩阵,找出其中最小值的元素所有的行和列,输出其值和所在行所在列!
- 3、JAVA建立一个5行4列的矩阵(数值直接在程序代码中给定),
- 4、java如何输入一个自定义矩阵
- 5、帮忙编写一个java程序,建立一个矩阵,并能返回其中一个元素周围的值..
- 6、java写用随机数建立一个3×4的矩阵,并查找矩阵中最大值
JAVa编写程序,建立并输出一个10*10的矩阵怎么做
没看到你的图,试试下面这个是不是你想要的:
#include
int main()
{
int i ,j;
int a[10][10];
for(i=0;i10;i++)
for(j=0;j10;j++)
{
a[i][j]=0;
if(i==(9-j)j==(9-i))a[i][j]=1;
if(i==j)a[i][j]=1;
}
for(i=0;i10;i++)
{
for(j=0;j10;j++)
{
printf("%i ",a[i][j]);
}
printf("\n");
}
getch();
}
(JAVA)建立一个m行n列的矩阵,找出其中最小值的元素所有的行和列,输出其值和所在行所在列!
现在假设你有个M行N列已初始化的而为数组array[m][n]。我帮你写找出最小值和位置的算法。int x = 0,y = 0,reset = array[0][0];for(int i=0;im;i++){ for(int j=0;jn;j++){ if(resetarray[i][j]){ reset = array[i][j]; x = i; y = j } }}System.out.println("最小值是:"+reset);System.out.println("最小值位置在第"+x+"行,第"+y+"列");
JAVA建立一个5行4列的矩阵(数值直接在程序代码中给定),
public class TestMatrix {
public static void main(String[] args){
int[][] a = {{2,4,1,4},{3,4,5,6},{0,1,2,3},{5,3,9,8},{1,2,3,4}};
int min = a[0][0];
int max = a[0][0];
int minrow = 0;
int mincol = 0;
int maxrow = 0;
int maxcol = 0;
for(int i = 0;i 5;i++){
for(int j = 0;j 4;j++){
if(a[i][j] = min){
min = a[i][j];
minrow = i;
mincol = j;
}
if(a[i][j] max){
max = a[i][j];
maxrow = i;
maxcol = j;
}
}
}
System.out.println("Min is:" + min + " Row is:" + minrow + " col is:" + mincol);
System.out.println("Max is:" + max + " Row is:" + maxrow + " col is:" + maxcol);
}
}
java如何输入一个自定义矩阵
java中自定义矩阵:
public static void main(String[] args) {
// TODO Auto-generated method stub
int n= 5;//长度
int array_int[][] = new int[n][n];
//初始化
for(int i=0;in;i++){
for(int j=0;jn;j++){
if(i==0){
if(j%2==0){
array_int[i][j] = (j+1)*(j+1);
}
else{
array_int[i][j] = array_int[i][j-1]+1;
}
}
else if(j==0){
if(i%2==1){
array_int[i][j] = (i+1)*(i+1);
}
else {
array_int[i][j] = array_int[i-1][j]+1;
}
}
else{
if(ij){
if(j%2==0){
array_int[i][j] = array_int[0][j]-i ;
}
else{
array_int[i][j] = array_int[0][j]+i ;
}
}
else{
if(i%2==0){
array_int[i][j] = array_int[i][0]+j ;
}
else{
array_int[i][j] = array_int[i][0]-j ;
}
}
}
//System.out.println(i+" "+j+":"+array_int[i][j] );
}
}
for(int i=0;in;i++){
for(int j=0;jn;j++){
System.out.print(array_int[i][j]+ " " );
}
System.out.println();
}
}
当等于5时的运行结果:
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
帮忙编写一个java程序,建立一个矩阵,并能返回其中一个元素周围的值..
public class MatrixNeighbors {
private int rows;
private int columns;
private int[][] matrix = new int[rows][columns];
public int[][] getMatrix() {
return matrix;
}
public void setMatrix(int[][] matrix) {
this.matrix = matrix;
}
public MatrixNeighbors(int rows, int columns) {
super();
this.rows = rows;
this.columns = columns;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public int getColumns() {
return columns;
}
public void setColumns(int columns) {
this.columns = columns;
}
public String neighbours(int row, int column) {
String result = "prints: ";
if (row = rows - 1 column = columns - 1 row = 0 column = 0) {
for (int i = row - 1; i = row + 1; i++) {
for (int j = column - 1; j = column + 1; j++) {
if (i = 0 j = 0 i = rows - 1 j = columns - 1) {
if (i == row j == column) {
} else {
result += i + "," + j + "; ";
}
}
}
}
} else {
return "Error!";
}
return result;
}
}
public class Test {
public static void main(String[] args) {
MatrixNeighbors m1 = new MatrixNeighbors(2, 3);
System.out.println(m1.neighbours(1, 1));
MatrixNeighbors m2 = new MatrixNeighbors(5, 4);
System.out.println(m2.neighbours(4, 3));
System.out.println(m2.neighbours(4, 4));
}
}
java写用随机数建立一个3×4的矩阵,并查找矩阵中最大值
代码如下:
import java.util.Random;
public class App26 {
static int[][] creat() {
int[][] arr = new int[3][4];
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i 3; i++) {
for (int j = 0; j 4; j++) {
arr[i][j] = random.nextInt(100);
}
}
return arr;
}
static void output(int[][] arr) {
for (int i = 0; i 3; i++) {
for (int j = 0; j 4; j++) {
System.out.print(String.format("%2d ", arr[i][j]));
}
System.out.println();
}
}
public static void main(String[] args) {
int[][] arr = creat();
int max = Integer.MIN_VALUE;
for (int i = 0; i 3; i++) {
for (int j = 0; j 4; j++) {
if (arr[i][j] max) {
max = arr[i][j];
}
}
}
System.out.println("矩阵中最大值是:" + max);
output(arr);
}
}
关于java建立矩阵和java建立矩阵,其初值为的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。