I am trying to create an "algorithm" (what I have now really isn't), I just can't seem to wrap my head around the concept, or on how to do this.. Here is the monstrosity I have created so far:
package org.buchanan.math; import java.util.ArrayList; import java.util.List; public class Numbers { private List<Integer> oddNumbers = new ArrayList<Integer>(); private List<Integer> evenNumbers = new ArrayList<Integer>(); public void populateLists() { for (int j = 0; j < Integer.MAX_VALUE; j += 1) { this.oddNumbers.add(j); System.out.println(j); } System.out.println("Odd numbers added!"); for (int i = 0; i < Integer.MAX_VALUE; i += 2) { this.evenNumbers.add(i); } System.out.println("Even numbers added!"); } public boolean isOddNumber(int n) { return this.oddNumbers.contains(n) ? true : false; } public boolean isEvenNumber(int n) { return this.evenNumbers.contains(n) ? true : false; } }
As you see, this destroys my memory, is slow as all get out, and not efficient in any way. Anybody have any suggestions on how to make this? Maybe even somewhere easier to start learning things like this?