Skip to content

Instantly share code, notes, and snippets.

@thmain
Created January 10, 2021 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/3725e04316955ec1055bd7da30c22171 to your computer and use it in GitHub Desktop.
Save thmain/3725e04316955ec1055bd7da30c22171 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class ThreeConsecutivesOdds {
public static boolean check(int[] input) {
int count = 0;
for(int i=0;i<input.length;i++){
if(input[i]%2!=0)
count++;
else
count = 0;
if(count==3)
return true;
}
return false;
}
public static void main(String[] args) {
int [] nums = {2, 4, 1, 3, 4, 1, 3, 6};
System.out.println(Arrays.toString(nums) + ", three consecutive odds: " + check(nums));
int [] nums_1 = {2, 4, 1, 3, 4, 1, 3, 5, 6};
System.out.println(Arrays.toString(nums) + ", three consecutive odds: " + check(nums_1));
int [] nums_2 = {2, 4, 1, 3, 4, 9, 1, 3, 0};
System.out.println(Arrays.toString(nums) + ", three consecutive odds: " + check(nums_2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment