Skip to content

Instantly share code, notes, and snippets.

@CalicoCatalyst
Created September 4, 2017 00:29
Show Gist options
  • Save CalicoCatalyst/cb749de2b18548760c3a5f08f627ffeb to your computer and use it in GitHub Desktop.
Save CalicoCatalyst/cb749de2b18548760c3a5f08f627ffeb to your computer and use it in GitHub Desktop.
GenRanNum
package net.insxnity.genrannum;
import java.util.Arrays;
import java.util.Random;
public class GenRanNum {
/* public static void main(String[] args) {
// Using the method of a separate main class allows you to configure multiple bots,
// And additionally, to pass any needed arguments to each bot
JBotLibTest jBotLibTestBotObject = new JBotLibTest();
jBotLibTestBotObject.run();
}*/
public static void main(String[] args)
{
int[] randomNumbers = new int[20];
randomNumbers = generateRandom(20);
System.out.print("Array:");
printArray(randomNumbers);
System.out.println("Reversed:");
printArray(reverse(randomNumbers));
System.out.println("Sorted");
printArray(sortArray(randomNumbers));
System.out.println("Adjacent Duplicates?: ");
System.out.println(adjacentDuplicates(randomNumbers));
System.out.println("Duplicates at all?:");
System.out.println(adjacentDuplicates(sortArray(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 int[] sortArray(int[] genNumbers)
{
Arrays.sort(genNumbers);
return 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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment