What is array with binary values? If an array contains only 0 and 1, it is called binary array.
import java.util.*;
class Arr
{
int arr[][]=new int [3][4];
int i,j,c;
Scanner sc=new Scanner(System.in);
public void show()
{
c=0;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print("\nValue:");
arr[i][j]=sc.nextInt();
}
}
System.out.print("\nValues=");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]!=0 || arr[i][j]!=1)
{
c=1;
break;
}
}
}
if(c==0)
System.out.print("\nArray with binary values");
else
System.out.print("\nArray with not binary values");
}
}
class Arr
{
int arr[][]=new int [3][4];
int i,j,c;
Scanner sc=new Scanner(System.in);
public void show()
{
c=0;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print("\nValue:");
arr[i][j]=sc.nextInt();
}
}
System.out.print("\nValues=");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]!=0 || arr[i][j]!=1)
{
c=1;
break;
}
}
}
if(c==0)
System.out.print("\nArray with binary values");
else
System.out.print("\nArray with not binary values");
}
}
No comments:
Post a Comment