I made this piece of code that should ask the user enter the length of first arrays that will contain how much numbers that he want, than recieving every number untill the amount is done. after that he need to ask for the length of digits array, and than recieving the digits. than, I need to check if all the numbers contain all the digits, if its true, print it, if not, print false. In this code I already replace the int[] with string arrays, Because I think this is the way it whould work. when I tried to make an Int arrays, with only single digit numbers, It works great, The problem comes when you want number like 22 with 2 digits, the checking breaks and not working.
String numInNumbersArray,
digitInDigitsArray;
int counterNumbers=0;
System.out.println("Please enter the length of the numbers array: ");
int numbersLength=s.nextInt();
String[] numbersArray=new String [numbersLength];
System.out.printf("Please enter %d numbers: ",numbersLength);
for(int i=0;i<numbersArray.length;i++){
numInNumbersArray=s.next();
numbersArray[i]=numInNumbersArray;
}
System.out.println("Please enter the length of the digits array: ");
int digitsLength=s.nextInt();
String[] digitsArray=new String [digitsLength];
System.out.printf("Please enter %d digits between 0 - 9 and - if you want: ",digitsLength);
for(int i=0;i<digitsArray.length;i++){
digitInDigitsArray=s.next();
digitsArray[i]=digitInDigitsArray;
}
for(int i=0;i<digitsArray.length;i++){
for(int j=0;j<numbersArray.length;j++){
if(numbersArray[j].equals(digitsArray[i])){
counterNumbers++;
}
}
}
if(counterNumbers==numbersArray.length){
System.out.println("true\n");
}else{
System.out.println("false\n");
}
So I obviously need a String array, But I have no idea how to continue from here to check every digit from a number. ( I cannot use advanced methods, Only simple checks). Your help or tuning would be great. thanks.
EDIT: It must be string because it also maight contain '-' (negetive numbers) to make it more clealry to understand I will add examples:
digits arrays for example : (1,2,-,3)
and numbers array : (1,-2,3)
this should return true.
and digits: (1,2,3)
numbers: (12,-3,123)
should return false.