I defined an array which contains random numbers.I get some numbers from the user and put them in other array.I want to check whether first array contains the second array in order.My code is not enough to check order.It is just checking contains or not. EX:
arr1=[45, 21,1,19 ,8,90,21,2] ,arr2=[21,1,19] result=TRUE
arr1=[45,21,1,19,8,90,21,2] ,arr2=[21,19] result=FALSE
public class Main {
private static int[] array1;
public static int[] list() {
array1 = new int[10];
for(int i=0;i<array1.length;i++)
{
array1[i] = randomFill();
}
return array1;
}
public static void print()
{
for(int n: array1)
{
System.out.println(n+" ");
}
}
public static int randomFill()
{
Random rand = new Random();
int randomNum = rand.nextInt(90)+10; //to generate two digits number which is between 10-99 to the array
return randomNum;
}
public static void main(String args[])
{
list();
print();
Scanner s=new Scanner(System.in);
System.out.println("How many numbers will you add? ");
int n=s.nextInt();
int array2[]=new int[n];
System.out.println("Enter the numbers:");
for(int i=0;i<n;i++){//for reading array
array2[i]=s.nextInt();
}
for(int i: array2){ //for printing array
System.out.println(i);
}
int result=0;
for(int i=0;i<array1.length;i++)
{
for(int j=0;j<array2.length;j++)
{
if(array1[i]==array2[j])
{
result=result+1;
}
}
}
if(result==n)
{
System.out.println("TRUE");
}
else
{
System.out.println("false");
}
}
}