Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started