import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
{
int[] massivIntov = {1,2,3};
int elementInt = 2;
System.
out.
println(najtiElementVMassive
(massivIntov,elementInt
));
double[] massivDoublov = {1,2,3};
double elementDouble = 2;
System.
out.
println(najtiElementVMassive
(massivDoublov,elementDouble
));
String[] massivStringov
= {"odin",
"dva",
"tri"}; System.
out.
println(najtiElementVMassive
(massivStringov,elementString
));
System.
out.
println(najtiElementVMassive
(massivIntegerov,elementInteger
));
// !!!
int[][] massivMassivIntov = {{1,2,3},{2,3,4},{3,4,5}};
int elementMassivIntov[] = {2,3,4};
System.
out.
println(najtiElementVMassive
(massivMassivIntov,elementMassivIntov
));
String[][][] massivMassivMassivStringov
= {{{"a"},
{"b"}},
{{"c",
"d"}},
{{"e",
"f"}}}; String[][] elementMassivMassivStringov
= {{"c",
"d"}}; System.
out.
println(najtiElementVMassive
(massivMassivMassivStringov,elementMassivMassivStringov
));
String[][] oshibochniiElementMassivMassivStringov
= {{"c",
"e",
"z"}}; System.
out.
println(najtiElementVMassive
(massivMassivMassivStringov,oshibochniiElementMassivMassivStringov
)); }
// -1 esli NotFound, snachala massiv potom element
static int najtiElementVMassive
(Object massiv,
Object element
){ if(massiv instanceof int[]) {
for(int i=0; i<((int[])massiv).length; ++i)
if(((int[])massiv)[i]==(int)element)
return i;
} else if(massiv instanceof byte[]) {
for(int i=0; i<((byte[])massiv).length; ++i)
if(((byte[])massiv)[i]==(byte)element)
return i;
} else if(massiv instanceof boolean[]) {
for(int i=0; i<((boolean[])massiv).length; ++i)
if(((boolean[])massiv)[i]==(boolean)element)
return i;
} else if(massiv instanceof char[]) {
for(int i=0; i<((char[])massiv).length; ++i)
if(((char[])massiv)[i]==(char)element)
return i;
} else if(massiv instanceof float[]) {
for(int i=0; i<((float[])massiv).length; ++i)
if(((float[])massiv)[i]==(float)element)
return i;
} else if(massiv instanceof double[]) {
for(int i=0; i<((double[])massiv).length; ++i)
if(((double[])massiv)[i]==(double)element)
return i;
} else if(massiv instanceof short[]) {
for(int i=0; i<((short[])massiv).length; ++i)
if(((short[])massiv)[i]==(short)element)
return i;
} else if(massiv instanceof long[]) {
for(int i=0; i<((long[])massiv).length; ++i)
if(((long[])massiv)[i]==(long)element)
return i;
} else {
try {
for(int i
=0; i
<((Object[])massiv
).
length; ++i
) if(sravnitMassivi
(((Object[])massiv
)[i
],element
)) return i;
for(int i
=0; i
<((Object[])massiv
).
length; ++i
) if((((Object[])massiv
)[i
]).
equals(element
)) return i;
}
}
return -1;
}
static boolean sravnitMassivi
(Object massiv1,
Object massiv2
) { try {
if((((Object[])massiv1
)).
length!=(((Object[])massiv2
)).
length) return false; boolean ravni=true;
for(int i
=0; i
<(((Object[])massiv1
)).
length; ++i
) ravni
=ravni
&&sravnitMassivi
((((Object[])massiv1
))[i
],
(((Object[])massiv2
))[i
]); return ravni;
if(massiv1 instanceof int[]) {
return Arrays.
equals((int[])massiv1,
(int[])massiv2
); } else if(massiv1 instanceof byte[]) {
return Arrays.
equals((byte[])massiv1,
(byte[])massiv2
); } else if(massiv1 instanceof boolean[]) {
return Arrays.
equals((boolean[])massiv1,
(boolean[])massiv2
); } else if(massiv1 instanceof char[]) {
return Arrays.
equals((char[])massiv1,
(char[])massiv2
); } else if(massiv1 instanceof float[]) {
return Arrays.
equals((float[])massiv1,
(float[])massiv2
); } else if(massiv1 instanceof double[]) {
return Arrays.
equals((double[])massiv1,
(double[])massiv2
); } else if(massiv1 instanceof short[]) {
return Arrays.
equals((short[])massiv1,
(short[])massiv2
); } else if(massiv1 instanceof long[]) {
return Arrays.
equals((long[])massiv1,
(long[])massiv2
); } else {
return massiv1.equals(massiv2);
}
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRX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