i didn't have long to do this project,
so didn't have time to troubleshoot, so pretty much made the lamest excuse for a program ever.
i turned in one where i handcoded 3 20 row/2 column arrays because i couldn't figure out how to make my method work.
it was already due, but i want to know why i'm a fucktard.
CODE
import java.util.*;
public class LCMa {
// This part was an attempt to get a method to establish an array
// with prime numbers, but I could not get it to run, so had to do
// it in the time and memory intensive way below
public int[][] arrayMaker(int y)
{
int[][] primesArray = new int[(y/2)][2];
int numberOfPrimes = y/2;
int count = 0;
int num =2;
while(count < numberOfPrimes){
boolean isPrime = true;
for(int divisor = 2; divisor <= num/2; divisor++){
if(num % divisor == 0){
isPrime = false;
break;
}
}
if (isPrime){
primesArray[count][0] = num;
count++;
num++;
}}
return primesArray;
}
//This begins the working portion of the program
public static void main(String[] args){
System.out.println("Please enter two integers :"); //Prompt for input
Scanner scan = new Scanner(System.in); // Establish Scanner
int numberOne = scan.nextInt();
int numberTwo = scan.nextInt();
int biggestNum = 0;
if(numberOne > numberTwo)
{
biggestNum = numberOne;
}
else{
biggestNum = numberTwo;
}
LCMa table1 = new LCMa();
int[][] numberOneTable = new int[biggestNum/2][2];
numberOneTable = table1.arrayMaker(biggestNum);
LCMa table2 = new LCMa();
int[][] numberTwoTable = new int[biggestNum/2][2];
numberTwoTable = table2.arrayMaker(biggestNum);
LCMa finalArrays = new LCMa();
int[][] finalArray = new int[biggestNum/2][2];
finalArray = finalArrays.arrayMaker(biggestNum);
// this loop grabs the first prime number in the list,
// and sees if it works for the number one
//
for (int i = 0; i < 10; i++){
while(numberOne % numberOneTable[i][0] == 0){
numberOneTable[i][1] += 1;
numberOne = (numberOne/numberOneTable[i][0]);
}
}
for (int j = 0; j < 10; j++){
while(numberTwo % numberTwoTable[j][0] == 0){
numberTwoTable[j][1] += 1;
numberTwo = (numberTwo/numberTwoTable[j][0]);
}
}
for(int k =0; k < 10; k++){
if(numberOneTable[k][1] > numberTwoTable[k][1]){
finalArray[k][1] = numberOneTable[k][1];
}
else{
finalArray[k][1] = numberTwoTable[k][1];
}
}
int total = 1;
System.out.print("1");
for(int m =0; m < finalArray.length; m++){
for(int n =0; n < finalArray[m][1]; n++){
System.out.print(" x " + finalArray[m][0]);
total *= finalArray[m][0];
}
}
System.out.println("\n" + "LCM is : " + total);
}
}
what would be the correct way to make use of that makeArray method.
i have till 9 to finish it but am at work.
son of a..... i better get on a comp there.