网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java二维数组的代码 java二维数组foreach

求用java写一个二维数组程序

public static void main(String[] args) {

我们拥有十余年网页设计和网站建设经验,从网站策划到网站制作,我们的网页设计师为您提供的解决方案。为企业提供网站设计、网站制作、微信开发、小程序定制开发手机网站制作成都h5网站建设、等业务。无论您有什么样的网站设计或者设计方案要求,我们都将富于创造性的提供专业设计服务并满足您的需求。

int[][] array = new int[60][60];

int sun = 0; //记录放入的总数

Random random = new Random(); //随机工具类

int math = random.nextInt(100); //得到一个参数

for(int i=0; iarray.length; i++){

for(int j=0; jarray[i].length; j++){

int tmp = random.nextInt(10);

if(tmp % 10 != 1){

array[i][j] = math;

sun ++;

if(sun =300){

break;

}

}

if(sun =300){

break;

}

}

}

JAVA 编写 二维数组

完整代码如下:

import java.util.Scanner;

/**

* @author young

*

*/

public class ArrTest {

public static void main(String[] args) {

int m, n, count = 0;//行,列

Scanner sc = new Scanner(System.in);

System.out.println("输入行:");

m = sc.nextInt();

System.out.println("输入列: ");

n = sc.nextInt();

int[][] a = new int[m][n];

int[] b = new int[m*n];

//对数组赋值

for(int i = 0; i  m; i++){

for(int j = 0; j  n; j++){

a[i][j] = (int)(Math.random()*m*n);

System.out.print(" " +a[i][j]);

b[count] = a[i][j];

count ++;

}

}

//输出重复的数

System.out.println("\n重复的数为:");

for(int x = 0; x  b.length ; x++){

for(int y = x; y  b.length; y++){

if(b[x] == b[y]  x != y){

System.out.print(b[x] + " , ");

}

}

}

}

}

运行截图:

求java代码 二维数组的最大值

import java.util.Scanner;

public class TestArray {

public static void main(String[] args) {

int nums[][] = new int[3][4];

Scanner scanner = new Scanner(System.in);

System.out.println("请输入数字:");

for (int i = 0; i  3; i++) {

for (int j = 0; j  4; j++) {

try{

int tmpInt = scanner.nextInt();

nums[i][j] = tmpInt;

}catch (Exception e) {

System.out.println("输入的不是数字,请重新输入!");

scanner.nextLine();

j--;

}

}

System.out.println("第"+(i+1)+"行输入完毕");

}

int max = nums[0][0];

int x=0;

int y=0;

for (int i = 0; i  3; i++) {

for (int j = 0; j  4; j++) {

if(nums[i][j]max){

max = nums[i][j];

x = i;

y = j;

}

}

}

System.out.println("最大值为:"+max+",行下标为:"+x+", 列下标为:"+y);

}

}

java中的二维数组的长度怎么用代码表示?行的长度?

java的二维数据的长度可以使用如下代码表示:

int a[2][2];

int len1=a.length;行长度

int len2=a[i].length.列长度


当前题目:java二维数组的代码 java二维数组foreach
文章地址:http://bjjierui.cn/article/ddggpdi.html

其他资讯