import java.util.Scanner; public class PrimeNumbers { //This program will calculate and output all prime numbers in the range from 1 to 100 public static void main(String[] args) { int numFactors = 0; //counts how many factors a number has for(int num = 1; num <=100; num++) //num will be every number from 1 to 100. We use it to test { //every number in that range to see if it is prime. numFactors = 0; //Reset numFactors to 0 each time num gets a new value for(int x = 2; x < num; x++) //start at 2 and stop before x reaches num { if(num % x == 0) //if any number from 2 to num - 1 returns no remainder, its a factor { //System.out.println(x + " is a factor of " + num); numFactors++; } } if(numFactors == 0) System.out.print(num + " "); //else System.out.println(num + " is not prime"); } } }