You should already know that a prime number is a number that is only divisible by 1 and itself.

So, the most trivial way to check if p is prime is to check to make sure it's not divisible by any number from 1 to p. This will work fine.

We can make it faster by considering that if a number is divisible by 2, then it would be disivible by 4, 6, 8, etc, so we only need to check 2 and odd numbers.

We can futher make it faster by considering for each number we check under the square-root, we are also checking the dividand above the square root. Thus, we only need to check numbers from 2 to sqrt(n).

This is probably the fastest you'll get out of a 6 line implementation without getting too fancy.

One of the quickest ways is to check if n divided by 2....sqrt(n) results in an even number. If any of them do the number is not prime.
so:
detemine square root of n (rounded up)

loop through 2 to square root of n, dividing n by number. If even division occurs (modulo) n is not prime.

import java.util.Scanner;
public class LuckySevens {
private int diceLength;
private int rolls;
private int sides;
private int numRolls = 0;
public static void main (String [] args) {
Scanner reader ...

I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...