Are there any other ways to print the position of your element inside the array? Even[position in the array]=even numbers Odd[position in the array]=odd numbers
public class samt {
public static void main(String[] args){
int Num[] = {1,2,3,4,5,6,7,8,9,10};
int ctr=1, ctr2=0;
for(int i=0;i<10;i++) {
if(Num[i]%2==0) {
System.out.print("Even"+"["+ctr+"]=");
System.out.println(Num[i]);
ctr+=2;
}
}
for(int i=0;i<10;i++) {
if(Num[i]%2!=0) {
System.out.print("Odd"+"["+ctr2+"]=");
System.out.println(Num[i]);
ctr2+=2;
}
}
}
}
StringBuilderand print the result at the end.