Hi,
I am supose to create a program that asks the user to input a number, and it will print out every prime less than or equal to the entered number. I have a few errors everytime I try to compile it.
will someone please help me figure out what my errors are? I have been working on this for awhile now and i finally got it down to a few syntax errors but I just can't figure out what they are.
here's what i've got so far:
import javax.swing.*;
public class Problem1 {
public static void main( String[] args ) {
int max = Integer.parseInt( JOptionPane.showInputDialog(
"Largest number that you want to test for primality." ) );
System.out.print( "Primes <= " max " are:" );
computePrimes( max );
}
public static void computePrimes( int m ) {
for ( int i = 1; i =< m; i ) {
if ( isPrime( i ) ) {
System.out.print( i ", " );
}
}
}
public static boolean isPrime( int ) {
if ( i == 1 ) {
return true;
}
for ( int j = 2; j <= i/2; j ) {
if ( ( i mod j ) == 0 ) {
return false;
}
}
return true;
}
}
Tags: