integer array has given. Even numbers should in even indexes and odd numbers should in odd indexes. you have to check whether given array is satisfied that condition.
my implementation is here….
public void isSatisfied(int [] arr){
for(int i=0;i<arr.length;i++){
int r_val=arr[i]%2;
int r_index=i%2;
if((r_val==1)&&(r_index==1)){
if(i==arr.length-1){
System.out.println("yes");
}
continue;
}
else if((r_val==0)&&(r_index==0)){
if(i==arr.length-1){
System.out.println("yes");
}
continue;
}
else{
System.out.println("no");
break;
}
}
}
what will be the best implementation?
The sum of a particular index and the value at that index must be even, otherwise the array doesn’t satisfy your condition: