public class Test
{
public static void main(String[] args) throws ParseException
{
int[] apple = {-2,2,1};
int[] orange = {5,-6};
countApplesAndOranges(7,11,5,15,apple,orange);
}
private static void countApplesAndOranges(int s, int t, int a, int b, int[] apple, int[] orange) {
int apple_length = apple.length;
int orange_lrngth = orange.length;
List<Integer> lstApple = new ArrayList<>();
List<Integer> lstOrange = new ArrayList<>();
for (int i = 0; i < apple_length; i++) {
int length = a + (apple[i]);
lstApple.add(length);
}
for (int i = 0; i < orange_lrngth; i++) {
int length = b + (orange[i]);
lstOrange.add(length);
}
//System.out.println(lstApple);
//System.out.println(lstOrange);
int countApple=0;
int countOrange=0;
for (Iterator iterator = lstApple.iterator(); iterator.hasNext();) {
Integer integer = (Integer) iterator.next();
if(integer>=s && integer<=t) {
countApple++;
}
}
for (Iterator iterator = lstOrange.iterator(); iterator.hasNext();) {
Integer integer = (Integer) iterator.next();
if(integer>=s && integer<=t) {
countOrange++;
}
}
System.out.println(countApple);
System.out.println(countOrange);
}
}
{
public static void main(String[] args) throws ParseException
{
int[] apple = {-2,2,1};
int[] orange = {5,-6};
countApplesAndOranges(7,11,5,15,apple,orange);
}
private static void countApplesAndOranges(int s, int t, int a, int b, int[] apple, int[] orange) {
int apple_length = apple.length;
int orange_lrngth = orange.length;
List<Integer> lstApple = new ArrayList<>();
List<Integer> lstOrange = new ArrayList<>();
for (int i = 0; i < apple_length; i++) {
int length = a + (apple[i]);
lstApple.add(length);
}
for (int i = 0; i < orange_lrngth; i++) {
int length = b + (orange[i]);
lstOrange.add(length);
}
//System.out.println(lstApple);
//System.out.println(lstOrange);
int countApple=0;
int countOrange=0;
for (Iterator iterator = lstApple.iterator(); iterator.hasNext();) {
Integer integer = (Integer) iterator.next();
if(integer>=s && integer<=t) {
countApple++;
}
}
for (Iterator iterator = lstOrange.iterator(); iterator.hasNext();) {
Integer integer = (Integer) iterator.next();
if(integer>=s && integer<=t) {
countOrange++;
}
}
System.out.println(countApple);
System.out.println(countOrange);
}
}