So Ive been instructed to write a class that generates an array (with return), sorts the generated array, reverses the sorted array (with return), and then check the sorted to see if any 2 adjacent #'s are the same (return True if there are, or False if there aren't).
I've managed to write everything out so far from what I can tell however my last set of instructions are to fill main with print statements that call on the lower methods I wrote to be displayed in the order written.
I managed to get the original randomly generated array to be called and printed, however I've had no luck at all on calling any of the other methods like I did the first and have tried everything I can think of to get them to just print their results with the provided "This is the blah blah blah:"
If anyone could point me in the right direction as far as being able to call the other methods to print their results, along with each print out to include a basic statement like "The Random array is: ", "The Sorted array is: ", "The Reversed array is: ", "It is (TRUE/FALSE) this array has adjacent duplicates." I would be very much appreciative. Nothing I've tried at this point has worked and im at a complete standstill. I've been trying to work friends who are familiar with java as well but we seem to be stuck too. This is what I've written so far...
import java.util.*;
public class SortedSequence
{
public static void main(String[] args)
{
int[] randomNumbers = new int[20];
randomNumbers = generateRandom(20);
printArray(randomNumbers);
// This is where Im getting stuck at. Everything I've tried makes a compile error
}
public static int[] generateRandom(int n)
{
int[] genNumbers = new int[n];
Random rand = new Random();
for (int i = 0; i < genNumbers.length; i++)
{
int bubble = rand.nextInt(100);
genNumbers[i] = bubble;
}
return genNumbers;
}
public static void sortArray(int[] genNumbers)
{
Arrays.sort(genNumbers);
}
public static int[] reverse(int[] x)
{
int[] sortArray = new int[x.length];
for (int i = 0; i < x.length; i++) {
sortArray[i] = x[x.length - 1 -i];
}
return sortArray;
}
public static boolean adjacentDuplicates(int[] boo)
{
boolean duplicates = false;
for (int i = 0; !duplicates && i < boo.length-1; i++)
if (boo[i] == boo[i+1]);
{
duplicates = true;
}
return duplicates;
}
public static void printArray(int[] print)
{
for (int i = 0; i < print.length; i++) {
System.out.print(print[i] + " "); }
System.out.println();
}
}
So I got the 3 int arrays to print.
Not sure how to get the boolean T or F to print from main...
Also not sure how I manged to get the initial random array to print on the same line as the the txt i needed to present prior to the array but it did, especially with all the other code being identical and not doing the same thing...
Recommendations on getting the arrays to print on same line as the the descriptive text? What about my boolean situation?