Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* This program checks an array of integers to see if there is duplicate integers adjacent to * one another in the array * For

* This program checks an array of integers to see if there is duplicate integers adjacent to
* one another in the array
* For example, if the array contains:
* 1, 2, 3, 4, 4, 6, 7, 8, 9, 42
*
* then the number 4 occurs at index 3 and index 4 in the array therefore adjacent duplicate is true
*
* If the array contains:
* 2, 1, 3, 4, 5, 4, 7, 4, 9, 4
*
* then even though the number 4 occurs multiple times, no occurrence of 4 is adjacent to another occurrence
*/
public class AdjacentDupes
{

/*
 *
*/
public static boolean adjacentDupes(int[] arr)
{
//-----------Start below here. To do: approximate lines of code = 5
// Loop through the array arr, checking for duplicates
// adjacent to each other. if duplicates occur, return true, else return false
//Hint: in the for loop, make sure you use a loop condition something like
// i < arr.length - 1 rather than i < arr.length  Why??
//Hint 2: as soon as you find a duplicate you can immediately return true


// Loop through array, checking for duplicates
// next to each other.








//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
int[] arr1 = {1, 2, 3, 4, 4, 6, 7, 8, 9, 42};
int[] arr2 = {2, 1, 3, 4, 5, 4, 7, 4, 9, 4};

// Check if array 1 has adjacent dupes.
if (adjacentDupes(arr1))
{
System.out.println("Array contains adjacent duplicates.");
}
else
{
System.out.println("Array does NOT contain adjacent duplicates.");
}
System.out.println("Expected:Array contains adjacent duplicates.");

// Check if array 2 has adjacent dupes.
if (adjacentDupes(arr2))
{
System.out.println("Array contains adjacent duplicates.");
}
else
{
System.out.println("Array does NOT contain adjacent duplicates." );
}
System.out.println("Expected:Array does NOT contain adjacent duplicates.");
}
}

P.S: Please include both the code results screenshot and the code so everything works. 

Le /* * This program checks an array of integers to see if there is duplicate integers adjacent to one another in the array * For example, if the array contains: 1, 2, 3, 4, 4, 6, 7, 8, 9, 42 * then the number 4 occurs at index 3 and index 4 in the array therefore adjacent duplicate is true * If the array contains: 2, 1, 3, 4, 5, 4, 7, 4, 9, 4 * then even though the number 4 occurs multiple times, no occurrence of 4 is adjacent to another occurrence */ = public class AdjacentDupes { public static boolean adjacentDupes (int[] arr) { ------Start below here. To do: approximate lines of code = 5 // Loop through the array arr, checking for duplicates // adjacent to each other. if duplicates occur, return true, else return false //Hint: in the for loop, make sure you use a loop condition something like // i < arr.length - 1 rather than i < arr.length Why?? //Hint 2: as soon as you find a duplicate you can immediately return true // Loop through array, checking for duplicates // next to each other.

Step by Step Solution

3.44 Rating (167 Votes )

There are 3 Steps involved in it

Step: 1

This program checks an array of integers to see if there is duplicate integers adjacent to one anoth... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probability & Statistics For Engineers & Scientists

Authors: Ronald E. Walpole, Raymond H. Myers, Sharon L. Myers, Keying

7th Edition

9789813131279, 130415294, 9813131276, 978-0130415295

More Books

Students also viewed these Programming questions

Question

Under what circumstances should derived associations be used?

Answered: 1 week ago