class ArrayDemo18
{
static void MaxOneRow(int x[][])
{
int i,j,temp,count[];
count = new int[x.length];
for(i=0;i<x.length;i++)
{
for(j=0;j<x[i].length;j++)
{
System.out.print(" "+x[i][j]+" ");
}
System.out.println();
}
for(i=0;i<x.length;i++)
{
temp = 0;
for(j=0;j<x[i].length;j++)
{
if(x[i][j] == 1)
{
temp++;
}
}
count[i]=temp;
}
temp = count[0];
j=0;
for(i=0;i<count.length;i++)
{
if(temp<count[i])
{
temp = count[i];
j = i;
}
}
System.out.println(" " + j);
}
public static void main(String... S)
{
MaxOneRow(new int[][]{{0,0,0,1,1},{0,0,1,1,1},{0,1,1,1,1},{0,0,0,0,1}});
}
}
{
static void MaxOneRow(int x[][])
{
int i,j,temp,count[];
count = new int[x.length];
for(i=0;i<x.length;i++)
{
for(j=0;j<x[i].length;j++)
{
System.out.print(" "+x[i][j]+" ");
}
System.out.println();
}
for(i=0;i<x.length;i++)
{
temp = 0;
for(j=0;j<x[i].length;j++)
{
if(x[i][j] == 1)
{
temp++;
}
}
count[i]=temp;
}
temp = count[0];
j=0;
for(i=0;i<count.length;i++)
{
if(temp<count[i])
{
temp = count[i];
j = i;
}
}
System.out.println(" " + j);
}
public static void main(String... S)
{
MaxOneRow(new int[][]{{0,0,0,1,1},{0,0,1,1,1},{0,1,1,1,1},{0,0,0,0,1}});
}
}
No comments:
Post a Comment