Question: public class ArrayOneTwoThree { public static boolean arrayOneTwoThree(int[] nums) { for (int i = 0; i < nums.length - 2; i++) { if (nums[i] ==

public class ArrayOneTwoThree { public static boolean arrayOneTwoThree(int[] nums) { for (int i = 0; i < nums.length - 2; i++) { if (nums[i] == 1 && nums[i + 1] == 2 && nums[i + 2] == 3) { return true; } } return false; } public static void main(String[] args) { int[] nums1 = {1, 1, 2, 3, 1}; System.out.println("arrayOneTwoThree([1, 1, 2, 3, 1]) " + arrayOneTwoThree(nums1)); int[] nums2 = {1, 1, 2, 4, 1}; System.out.println("arrayOneTwoThree([1, 1, 2, 4, 1]) " + arrayOneTwoThree(nums2)); int[] nums3 = {1, 1, 2, 1, 2, 3}; System.out.println("arrayOneTwoThree([1, 1, 2, 1, 2, 3]) " + arrayOneTwoThree(nums3)); } } Add one more number in code int[] nums4 {1, 2, 3, 1, 1, 2}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!