二维数组的问题 二维数组创建一个矩阵4x4的1111010101011011怎么取0位置的下标按行排的话是第几个?第一个0是4 第二0是6比如说0,1,2,31 1 1 14,5,6,70 1 0 18,9,10,110 1 0 1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在遍历的同时也可以用个int变量来一直记录索引 应该是(行号+1)*4+列号..吧 控制行的索引是从0开始的int a[]=new int[4];a[0]={1,1,1,1};a[1]={0,1,0,1};a[2]={0,1,0,1};a[3]={1,0,1,1};int count=0;//记录是第几个0;for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++) { if(a[i][j]==0) { count++; System.out.println("第"+count+"个0是"+((i+1)*4+j)); } }}不知道楼主要的是不是这个效果..随便写了一个! 6楼的答案是错的,试试这个:public static void main(String[] args) { int a[][] = { { 1, 1, 1, 1 }, { 0, 1, 0, 1 }, { 0, 1, 0, 1 }, { 1, 0, 1, 1 } }; int count = 0;// 记录是第几个0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { if (a[i][j] == 0) { count++; System.out.println("第" + count + "个0是" + (i * 4 + j)); } } } }运行结果:第1个0是4第2个0是6第3个0是8第4个0是10第5个0是13 public class myjava { /** * @param args */ public static void main(String[] args) { int a[][]=new int[][]{{1,1,1,1},{0,1,0,1},{0,1,0,1},{1,0,1,1}}; int count=0;//记录是第几个0; for(int i=0;i<a.length;i++) { for(int j=0;j<a[i].length;j++) { if(a[i][j]==0) { count++; System.out.println("第"+count+"个0是"+(i*4+j+1)); } } }}}我调用myeclipse调试过,结果是:第1个0是5第2个0是7第3个0是9第4个0是11第5个0是14 文件递归时,批量修改文件的名称 一个C/S软件的设计 Struts2 optiontransferselect标签老提示错误。。。。 访问串口的程序在jdk中运行正常,在eclipse中却不行 如何去掉查询出的hh-mm-ss 一个错误,请大家看看.从套接字读数据的问题!!急 linux系统 32位 64位 jdk1.6 下载 在线等待,急……用java打印,纸张右半边为何打印不出来 SCJP模拟题 about String Array 关于java实现的dbscan算法 急!!! 高手都来 JAVA求助
a[0]={1,1,1,1};
a[1]={0,1,0,1};
a[2]={0,1,0,1};
a[3]={1,0,1,1};
int count=0;//记录是第几个0;
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a[i].length;j++)
{
if(a[i][j]==0)
{
count++;
System.out.println("第"+count+"个0是"+((i+1)*4+j));
}
}
}不知道楼主要的是不是这个效果..随便写了一个!
public static void main(String[] args) { int a[][] = { { 1, 1, 1, 1 }, { 0, 1, 0, 1 }, { 0, 1, 0, 1 },
{ 1, 0, 1, 1 } };
int count = 0;// 记录是第几个0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
if (a[i][j] == 0) {
count++;
System.out.println("第" + count + "个0是" + (i * 4 + j));
}
}
}
}
运行结果:
第1个0是4
第2个0是6
第3个0是8
第4个0是10
第5个0是13
* @param args
*/
public static void main(String[] args) {
int a[][]=new int[][]{{1,1,1,1},{0,1,0,1},{0,1,0,1},{1,0,1,1}};
int count=0;//记录是第几个0;
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a[i].length;j++)
{
if(a[i][j]==0)
{
count++;
System.out.println("第"+count+"个0是"+(i*4+j+1));
}
}
}
}
}
我调用myeclipse调试过,结果是:
第1个0是5
第2个0是7
第3个0是9
第4个0是11
第5个0是14