/* * Main.java * Created on July 24, 2006, 10:24 AM */ package javaapplication3; import java.util.Scanner; import javax.swing.*; // For JFrame and JPanel import java.awt.*; // For Color, Container, and GridLayout import javax.swing.JOptionPane; public class Main { /** Creates a new instance of Main */ public Main() { } public static void primefact(int n) { int divisor = 2; int count =0; while (n > 1) { if (n % divisor == 0) { count++; n = n / divisor; if (count == 1) System.out.print(divisor); else System.out.print(" X " + divisor); } else { divisor = divisor + 1; } } if (count == 1) System.out.println(" PRIME!!!! "); else System.out.println(" "); } public static void main(String[] args) { String inputStr = JOptionPane.showInputDialog("Enter the start", "2"); if (inputStr == null) return; double start = Double.parseDouble(inputStr); inputStr = JOptionPane.showInputDialog("Enter the stop", "100"); if (inputStr == null) return; double stop = Double.parseDouble(inputStr); for (int x =(int)start; x <= (int)stop; x++) { System.out.print("the prime factors for " + x + " : "); primefact(x); } // JOptionPane.showMessageDialog(null, "Error: fahrenheit must be >= 0"); // JOptionPane.showMessageDialog(null, "The temp in Celsius is " + mystring); } }