Array in java, how to calculate hamming distance between String and int? - java

I have to write a programm.I am learning 2 month java and i am stuck.An advice how to forwoard on this is very helful for me.
The class will contain two methods, public static void main and public static int hamming.
The hamming method will accept two alphanumeric parameters and return an integer
number which is the Hamming distance of these two alphanumerics. For example, if as
given arguments “dog” and “dig” the method will return the integer 1, which is the distance
Hamming between them. In the event that the arguments do not have the same length, the method will
returns -1.
The main method will include as local variables an array of alphanumerics with 5 elements
and name stringList and an array of integers with 5 elements and name distances. main will execute them
following actions:
• It will read an extra alphanumeric, which it will store in a local variable with
target name.
• In an iterative process, it will calculate (by calling the hamming method) the distances
of the alphanumeric array stringList from the target and will store them in the corresponding ones
positions of the distances table (it will be either integer >=0 or -1 if n is not applied
distance due to different length).
• After the calculations it will go through the distances table and find the shortest one
distance that he includes. Of course, the value -1 will not be calculated.
• It will display (all) the contents of the distances table on the screen, as well as the
alphanumeric array stringList with the shortest distance from the target. If they exist
more than one case, it will display one.
Your program's screen output will look like the following samples
execution:
Example 1:
Enter string: dog
Enter string: cat
Enter string: jim
Enter string: bed
Enter string: toe
Enter target: house
Contents of array distances
0 -1
1 -1
2 -1
3 -1
4 -1
No Hamming distance found
Example 2:
Enter string: dog
Enter string: cat
Enter string: jim
Enter string: bed
Enter string: blackboard
Enter target: bid
Contents of array distances
0 3
1 3
2 2
3 1
4 -1
String with min Hamming distance: bed.
public class Thema3
{
public static void main (String[]args){
//Creating scanner object
Scanner stringList = new Scanner(System.in);
// creating String array of 5
String [] stringList1 = new String[6];
double[] targetString= {};
stringList1[1]="";
stringList1[2]="";
stringList1[3]="";
stringList1[4]="";
stringList1[5]="";
int sum=0;
//read input
boolean valid=true;
for (int i=1; i<6;i++)
{
System.out.print(+i+". Enter string:" );
stringList1 [i] =stringList.nextLine();
do {
valid = true;
if (stringList1==target1 ){
int[] array = new int[5];
Random rnd = new Random();
array[i]=rnd.nextInt();
}
}while (!valid);
Scanner target = new Scanner (System.in);
//creating target string
String target1 = target.nextLine();
System.out.println("Enter target:");
}
}
public static int hammingdistance(String target1,String stringList1) {
int distance=0;
if( target1.length() != stringList1.length())
{
return -1;
}
else
{
for(int i=0;i<target1.length();i++)
{
if(target1.charAt(i)!=stringList1.charAt(i))
distance++;
}
return distance;
}
}
public static void bubbleSort(int[]ar){
boolean sorted = false;
sorted = true;
for (int i=0;i<ar.length-1;i++)
if (ar[5]>ar[i+1]){
int tmp = ar[i];
ar[5]=ar[i+1];
ar[i+1]=tmp;
sorted = false;
}
}
}

import java.lang.*;
public class Main
{
public static void main(String[] args)
{
String [] strInput1 = {"After ","blackboard ","Contents ","distances","Hamming "};
String [] strInput2 = {"two ","static ","array ","local ","find "};
int [] intResult = new int [strInput2.length] ;
for (int i = 0 ; i< strInput2.length ; i++)
{
intResult[i] = Math.abs(strInput1[i].length() - strInput2[i].length());
System.out.println(intResult[i]);
}
}
}

Related

How to multiply different indexes by different values?

I am creating a scrabble game, where the characters get the same values as scrabble,(q & z =10),(k=5), etc, and the main issue that I am having is that I am asking the user to input 2 ints after the word, the first being the index of the bonus tile, and the second being the multiplier to multiply the word with. The value without the multiplier is correct, but the multiplier is not working.
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String word = kb.next();
int bonusI = kb.nextInt();
int bonusMult = kb.nextInt();
int score=0;
for (int i=0; i<word.length();i++){
int letterScore;
String letter=word.substring(i,i+1);
if (letter.equals("d")||letter.equals("g")){
letterScore=2;
}
else if (letter.equals("k")) {
letterScore=5;
}
else if (letter.equals("j")||letter.equals("x")){
letterScore=8;
}
else if (letter.equals("q")||letter.equals("z")) {
letterScore=10;
}
else {
letterScore=1;
}
for (int j=0;j<1;j++){
if (word.substring(i,i+1).equals(bonusI)){
letterScore*=bonusMult;
}
}
score+=letterScore;
}
System.out.println(score);
}
}
For example, if the input is dog 2 3 then the correct output would be 9,(d is 2 points,o according to scrabble is 1 point, and g is 2 points, but since the 1st int inputted was 2, and g has an index of 2, it is then multiplied by the bonus of 3, which makes g=6, adding them 2+1+6=9) but instead my output is 5 because the multiplier for g is not working.
Looks like you have a mistake here.
word.substring(i,i+1).equals(bonusI)
word.substring(i,i+1) is String and gives one letter
bonusI is an int and tives one number
This will never be true
if (word.substring(i,i+1).equals(bonusI)) - This condition will be always false as you can't compare a string with int value.
Instead you can just replace the internal for loop with below code
if (bonusI == i)
{
letterScore*=bonusMult;
}

Frequency Array and Histogram in Java

I have to make the following program.
Write a program that builds a frequency array for data values in the range 1 to 20 and then prints their histogram. The data is to be read as input from the user. Add the following functions to your program:
a. The getData function takes input from the user and stores the data in an array.
b. The printData function prints the data in the array.
c. The makeFrequency function examines the data in the array, one element at a time, and adds 1 to the corresponding element in a frequency array based on the data value.
d. The makeHistogram function prints out a vertical histogram using asterisks for each occurrence of an element. For example, if there were five value 1s and eight value 2s in the data, it would print
1: *****
2: ********
I managed to make getData function but I can't make the other 3. Any help would be appreciated. Here is my code
import java.util.Scanner;
public class FrequencyArray {
static Scanner scan = new Scanner(System.in);
public void getData() {
System.out.println("Enter the size of array: ");
int nums = scan.nextInt();
int[] a = new int[nums];
for (int i = 1; i < a.length; i++) {
System.out.print("Enter the numbers: " + i + ":");
a[i] = scan.nextInt();
}
}
public void printData() {
getData();
}
public static void main(String[] args) {
FrequencyArray array = new FrequencyArray();
array.getData();
}
}
To print such an array, all you would need is another for-loop - loop from 0 to the array's length, and print both the loop counter's value, and the value stored in the array at that index.
System.out.println(index + ":" + array[index]);
For the histogram, do a similar loop, but for each value of the array, append an asterisk to the current line for however many instances of said number there are.
System.out.print(index);
//from 0 to the amount of this number, call System.out.print("*");
System.out.println();
Use TreeMap to store the number and their frequency in a sorted order once you get the data
then iterate over the TreeMap to print the number followed by the stars denoting the count of the value
public void printData() {
int [] numArray = getData();
Map<Integer,Integer> valueCountMap = new TreeMap();
for(int i=0;i<numArray.length;i++) {
int num = numArray[i];
if(valueCountMap.get(num) == null) {
valueCountMap.put(num,0);
}
int count = valueCountMap.get(num);
valueCountMap.put(num,count+1);
}
for(Map.Entry<Integer,Integer> entry:valueCountMap.entrySet()) {
int num = entry.getKey();
int value = entry.getValue();
System.out.print(num+":");
for(int i=0;i<value;i++) {
System.out.print("*");
}
System.out.print(" ");
}
}
Following assumptions i have made getData must return interger array and you need to print in one line. Following rectification i have done to your code
in getData i = 0 not i = 1

What's the best method of finding integers in a string?

Hello StackOverflow community! I'm student trying to solve this problem....
The main issue I am having with it is that I dont know the best way to find characters that are valid integers in Strings.
Note: I am only 1 month into learning Java, and I spent most of last year learning python. So compiler languages are new to me.
Write a program that reads in a product code and outputs whether it is valid or not based on some simple rules.
The rules:
1st part can contain only capital letters and 6 digits. 2nd part is alldigits and = the product of the first 6 digits taken in groups of two from the left.
eg: AX6BYU56UX6CV6BNT7NM 287430
is valid because 65*66*67 = 287430
This is what I have so far
import java.util.*; //import java utilities
public class Basic5{ //declares my class
public static void main(String[]args){
Scanner kb=new Scanner(System.in);//creates Scanner for user input
String userentry=kb.nextLine(); //Takes users input as a string
String result="Valid"; //Variable for if the code is Valid
int DoubleCounter=0; //Counter for number of ints
double newdouble;
List<Double> NumberList = new ArrayList<Double>(); //Creates Array List for tracking Doubles
for(int i=0;i<userentry.length();i++){ //checks length of Users input
if(Character.isLowerCase(userentry.codePointAt(i))){ //checks if its a Lowercase letter
result="Fail"; //Changes result variable
if(Integer.parseInt(userentry,i)){ //checks if character from input is a valid integer
DoubleCounter+=1; //Adds to DoubleCounter
newdouble=userentry.charAt(i); //Isolates character
NumberList.add(newdouble); //Adds it to List of doubles
}
}
}
}
}
You can use following methods to check whether the input is a char or digit :
Character.isDigit('A');
Character.isLetter('A');
Here's one way to do it:
#Test
public void testExample() {
assertTrue(isValid("AX6BYU56UX6CV6BNT7NM 287430"));
assertFalse(isValid("AX6BYU56UX6CV6BNT7NM 287431"));
}
private boolean isValid(String s) {
String[] parts = s.split(" ");
int[] ints = extractIntegers(parts[0]);
int target = Integer.parseInt(parts[1]);
return product(ints) == target;
}
private int[] extractIntegers(String s) {
String digits = s.replaceAll("\\D+", "");
int[] ints = new int[digits.length() / 2];
for (int i = 0; i < digits.length(); i += 2) {
ints[i / 2] = Integer.parseInt(digits.substring(i, i + 2));
}
return ints;
}
private int product(int[] ints) {
int result = 1;
for (int num : ints) {
result *= num;
}
return result;
}
It assumes that there are non-zero even number of digits in the first part of the string. If you need to handle other cases, it should be easy to do, based on this.
String str = "AX6BYU56UX6CV6BNT7NM 287430";
str = str.replaceAll("[^0-9]+", "");

Java Program that reads in text file and compares it to user input

I'm having some trouble opening and reading in a simple input.txt file to a Java program I'm creating in one of my computer science classes (basic premise of the program is to take lottery data from the file, such as players name and their lottery numbers, and compare it to the user's number that are provided as input). First, when I compile and try to run the program (Eclipse IDE), it cannot see the input.txt file even though it is in the same directory. I have to type in "src/Assignment1/input.txt" in the command line for it to properly find the file. I looked in to the Path utility of Java to see if that could resolve it, but not sure how to implement that code or if there is an easier way.
Also, when the program does find the file, I have my readFile method taking the first number in the text file as the number of tickets sold, and then having a linked list created to hold the data for each person. I am getting a compile error in the second nested for loop in the readFile method shown below:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type lottery is accessible. Must qualify the allocation with an enclosing instance of type lottery (e.g. x.new A() where x is an instance of lottery).
at Assignment1.lottery.readFile(lottery.java:89)
at Assignment1.lottery.main(lottery.java:214)
I've provided a copy of what is in the input.txt below and my code as well under that, any guidance would be appreciated!
5
Llewellyn Mark
1 15 19 26 33 46
Young Brian
17 19 33 34 46 47
Guha Arup
1 4 9 16 25 36
Siu Max
17 19 34 46 47 48
Balci Murat
5 10 17 19 34 47
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
public class lottery {
// Enumeration method that holds constants for how many matches correlate to how much in winnings
public enum PayOut
{
MATCHTHREE(10), MATCHFOUR(100), MATCHFIVE(10000), MATCHSIX(1000000);
private int winnings;
public int getval()
{
return winnings;
}
private PayOut(int amount)
{
this.winnings = amount;
}
}
// Method call to create linked list with purchaser's data in each node
static LinkedList<PurchaserList> purchasers = new LinkedList<>();
// Data structure for purchaser information, contained in each node in linked list
public class PurchaserList
{
public String lastName;
public String firstName;
public int[] numbers;
public PurchaserList (String last, String first, int[] nums)
{
lastName = last;
firstName = first;
numbers = nums;
}
public String getLastName()
{
return lastName;
}
public String getFirstName()
{
return firstName;
}
public int[] getNumbers()
{
return numbers;
}
}
// Method to open and read in data from input file
public static void readFile (String file) throws IOException
{
File fileName = new File(file);
try
{
Scanner in = new Scanner(fileName);
int numTickets = in.nextInt();
for(int i = 0; i < numTickets; i++)
{
String lastName = in.next();
String firstName = in.next();
int[] numbers = new int[6];
for(int j = 0; j < 6; j++)
{
numbers[j] = in.nextInt();
}
PurchaserList current = new PurchaserList(lastName, firstName, numbers);
purchasers.add(i, current);
}
in.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
}
public static void compareNumbers(int[] winningNumbers)
{
// Creates array to hold winning numbers
List<Integer> winningNums = new ArrayList<>(); //creates a list to store all the winning numbers
// For loop to store winning numbers in prior array
for(int num : winningNumbers)
{
winningNums.add(num);
}
//For loop to go through each purchaser in the linked list and get their lottery numbers
for (PurchaserList purchaser : purchasers)
{
// Generating list that stores all the numbers from the current purchaser
List<Integer> playerNums = new ArrayList<>();
// For loop to add numbers to the list
for(int num : purchaser.getNumbers())
{
playerNums.add(num);
}
//Converts list in to a set
Set<Integer> similar = new HashSet<>(playerNums);
//Compares set of winning numbers to purchaser's numbers, keeps similar values
similar.retainAll(winningNums);
//Calls enum method to look for winning amount based on the numbers matched, returns enumeration
PayOut matchesFound = matches(similar.size());
//Only display winnings if matches are 3 or greater
if(matchesFound != null)
{
displayPrices(matchesFound, purchaser.getFirstName(), purchaser.getLastName(), similar.size());
}
}
}
public static PayOut matches(int num)
{
PayOut numMatches;
if(num == 3)
{
numMatches = PayOut.MATCHTHREE;
}
else if(num == 4)
{
numMatches = PayOut.MATCHFOUR;
}
else if(num == 5)
{
numMatches = PayOut.MATCHFIVE;
}
else if(num == 6)
{
numMatches = PayOut.MATCHSIX;
}
else
{
return null;
}
return numMatches;
}
private static void displayPrices(PayOut numMatches, String first, String last, int matches)
{
switch(numMatches)
{
case MATCHTHREE:
System.out.printf("%n%s %s matched %d numbers and won $%d. %n", first, last, matches, PayOut.MATCHTHREE.getval());
break;
case MATCHFOUR:
System.out.printf("%n%s %s matched %d numbers and won $%d. %n", first, last, matches, PayOut.MATCHFOUR.getval());
break;
case MATCHFIVE:
System.out.printf("%n%s %s matched %d numbers and won $%d.%n", first, last, matches, PayOut.MATCHFIVE.getval());
break;
case MATCHSIX:
System.out.printf("%n%s %s matched %d numbers and won $%d. %n", first, last, matches, PayOut.MATCHSIX.getval());
break;
default:
System.out.println("None of the players matched any numbers %n");
break;
}
}
// Main method
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
// Asking user for input file
System.out.println("Enter the name of the file with the ticket data: ");
String fileName = scan.nextLine();
//Method call to open and read in data from input file
readFile(fileName);
// Creates array to store winning lottery numbers
int[] winningNumbers = new int[6];
// Asking user for winning lottery numbers, in ascending order
System.out.println("Enter the winning Lottery numbers (in ascending order separated by spaces): ");
// For loop to scan in winning lottery numbers to array
for(int i = 0; i < 6; i++)
{
winningNumbers[i] = scan.nextInt();
}
//Method call to compare winning numbers to purchaser's numbers
compareNumbers(winningNumbers);
// Close input file
scan.close();
}
}
The PurchaserList class is not static. Therefore, it must be accessed like lotteryInstance.new PurchaserList() (because as it's not static, it belongs to Lottery instances).
So, making PurchaserList static should fix it.

Functions/Methods and Arrays

My class has just started learning how to write code in a format with functions and methods, and this is my first attempt at it - I feel like I'm just confusing myself.
The assignment is to create a pool of numbers 1 to a randomly selected number and to store the pool in an array; then print the pool; then a user selects a number from the pool, and the program finds the divisors of that number and stores them in another array that will then be printed.
I am having problems with getting the divisors, storing them in a new array and then printing the array.
import java.util.Scanner;
import java.util.Random;
public class GetDivisors {
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];
int []divisors = new int[100];
int size;
int pick;
int numDivisor;
// Program Heading
printProgramHeading();
// Input and test
size = createPool(pool);
printPool(pool, size);
System.out.println();
System.out.println();
System.out.println("Enter a non-prime value listed in the pool above: ");
pick=read.nextInt();
// Data Processing
numDivisor = getDivisors(pool, divisors, pick);
// Output Section
printDivisors(divisors, size, pick);
} // end main
// Function and Method Specifications
// Name : printProgramHeading
// Description : This method prints the program heading to the monitor in all caps and with a dividing line
// : followed by a blank line.
// Parameters : None.
// Return : None.
public static void printProgramHeading() {
System.out.println("\tGET DIVISORS");
System.out.println(" ************************");
System.out.println();
} // end printHeading
//Name : createPool
//Description : This funtion generates an array of consecutive integers from 1 to a randomly generated
// : number no greater than 100.
//Parameters : An integer array.
//Return : An integer (the randomly generated number), representing the size of the array.
public static int createPool(int[]pool) {
Scanner read = new Scanner(System.in);
Random random = new Random();
int size=0;
size=random.nextInt(100)+1;
pool=new int[size];
return(size);
} // end createPool
//Name : printPool
//Description : This method prints the pool of numbers to the monitor no more than 10 per line.
//Parameters : The pool array, and the size of the pool in that order.
//Return : None.
public static void printPool(int[] pool, int size) {
int index;
int count=0;
for(index=1; index<size; index++){
System.out.print(pool[index]=index);
System.out.print(" ");
count++;
if(count == 10){
System.out.println();
count=0;
} // end if loop
} // end for loop
} // end printPool
//Name : getDivisors
//Description : This funtion stores all the divisors of the user's pick into the divisor array.
//Parameters : The pool array, the divisor array, and the user's pic, in that order.
//Return : The number of divisors found.
public static int getDivisors(int[] pool, int[] divisors, int pick){
int numDivisors = 0;
int index = 0;
for(index=1; index <= pick; index++){
if(pick % index == 0){
numDivisors++;
divisors[index] = index;
} // end if loop
} // end for loop
return(numDivisors);
} // end getDivisors
//Name : printDivisors
//Description : This method prints the contents of the divisors array to the monitor all on one line with
// : a leading label.
//Parameters : The divisor array, an integer representing the number of divisors. and the user's pick
// : in that order.
//Return : None.
public static void printDivisors(int[] divisors, int size, int pick){
int index = 0;
System.out.println("The divisors of " + pick + ": " + divisors[index] + " ");
} // end printDivisors
} // end class
Thank you!
This is obviously a school project. In order for you to learn I don't want to give you the answers but i'll point out your mistakes, so that you can fix your problems.
First in this method createPool:
//Name : createPool
//Description : This funtion generates an array of consecutive integers from 1 to a randomly generated
// : number no greater than 100.
//Parameters : An integer array.
//Return : An integer (the randomly generated number), representing the size of the array.
public static int createPool(int[]pool) {
Scanner read = new Scanner(System.in);
Random random = new Random();
int size=0;
size=random.nextInt(100)+1;
pool=new int[size];
return(size);
} // end createPool
Look closer at the values that are stored in the array.
Second in method printPool:
//Name : printPool
//Description : This method prints the pool of numbers to the monitor no more than 10 per line.
//Parameters : The pool array, and the size of the pool in that order.
//Return : None.
public static void printPool(int[] pool, int size) {
int index;
int count=0;
for(index=1; index<size; index++){
System.out.print(pool[index]=index);
System.out.print(" ");
count++;
if(count == 10){
System.out.println();
count=0;
} // end if loop
} // end for loop
} // end printPool
You are updating the values of the pool. This method should only print the values in the pool. You should be setting the values of the pool in createPool, and printing the values of the pool in printPool.
Next in the getDivisors method
//Name : getDivisors
//Description : This funtion stores all the divisors of the user's pick into the divisor array.
//Parameters : The pool array, the divisor array, and the user's pic, in that order.
//Return : The number of divisors found.
public static int getDivisors(int[] pool, int[] divisors, int pick){
int num = 0;
int divisor = 0;
int numDivisors = 0;
int index = 0;
for(pool[index]=1; pool[index]<=pick; pool[index]){
num = pick % pool[index];
if(num == 0){
divisor = num;
numDivisors++;
divisors= new int[divisor];
} // end if loop
} // end for loop
return(numDivisors);
} // end getDivisors
You have a lot of things wrong with this method. First, re-look at your for loop. I really think you need to learn further about how for loop should operate and when is the best time for use for loops. Your underlying understanding of for loops in flawed. Your logic is right for calculating the divisor, but you have two issues related to this logic. 1) Relook at how you put the new divisor into the divisors array. This is related to the earlier issue of how you use the for loop. Once you solve the for loop problem, this should become more clear 2) What should you store into the divisors array when num == 0 is false? You need to handle this case, right?
Now onto the printDivisors method:
//Name : printDivisors
//Description : This method prints the contents of the divisors array to the monitor all on one line with
// : a leading label.
//Parameters : The divisor array, an integer representing the number of divisors. and the user's pick
// : in that order.
//Return : None.
public static void printDivisors(int[] divisors, int size, int pick){
int index = 0;
System.out.println("The divisors of " + pick + ": " + divisors[index] + " ");
} // end printDivisors
Once again, you really need to understand when and when-not to use a for loop. This method should print out all the values in the divisors array. Currently, this method only prints out one value in the divisors array (the first value, at index 0).
Finally, in the main() function:
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];
int []divisors = new int[100];
int size;
int pick;
int divisor;
// Program Heading
printProgramHeading();
// Input and test
size = createPool(pool);
printPool(pool, size);
System.out.println();
System.out.println();
System.out.println("Enter a non-prime value listed in the pool above: ");
pick=read.nextInt();
// Data Processing
divisor = getDivisors(pool, divisors, pick);
// Output Section
printDivisors(divisors, size, pick);
} // end main
Should int[] pool, and int[] divisors be initialized initially with an arbitrary size of 100? Random numbers like these are usually called "magic numbers". Magic numbers should either be set as a constant with a description, or taken out of the program. Next, you print the header. This seems ok. Then you create the pool, and save the pool size into size, and print the pool with the given size passed into the function. This all seems fine. Next you poll the user for a divisor input, and call the getDivisors function with the user input. Also you save the output into a variable divisor, which represent the size of the divisor array. Now, look at the parameters you pass into printDivisors, something smells fishy here...
These are all of the issues that I see with your code. This should give you plenty of information on how to improve your mistakes. If you have anymore questions please feel free to ask.
Sorry I can't comment your question. Is it ok if you use Collections instead of arrays?
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GetDivisorsRefactored {
private static Integer[] pool;
private static Scanner read;
public static void main(String[] args) {
// Program Heading
printProgramHeading();
initPool();
System.out.println("Available list: ");
printArray(pool);
read = new Scanner(System.in);
System.out.println();
System.out.println();
System.out.println("Enter a non-prime value listed in the pool above: ");
int pick=read.nextInt();
Integer[] divisors = findDivisors(pick);;
printArray(divisors);
}
private static void printArray(Integer[] someArray) {
int nextRow = 0;
for (int num: someArray){
System.out.printf("%4d,", num);
if (++nextRow > 9){
System.out.println();
nextRow =0;
}
}
}
private static Integer[] findDivisors(int pick) {
List<Integer> divisors = new ArrayList<Integer>();
for (int index = 1; index < pool.length; index++){
if ((pick % pool[index]) == 0){
divisors.add(pool[index]);
}
}
return divisors.toArray(new Integer[divisors.size()]);
}
private static void initPool() {
int size = (int) (Math.random()*100) + 1;
pool = new Integer[size];
for (int index = 0; index < pool.length; index++){
pool[index] = index;
}
}
// Function and Method Specifications
// Name : printProgramHeading
// Description : This method prints the program heading to the monitor in
// all caps and with a dividing line
// : followed by a blank line.
// Parameters : None.
// Return : None.
public static void printProgramHeading() {
System.out.println("\tGET DIVISORS");
System.out.println(" ************************");
System.out.println();
} // end printHeading
}

Categories