/ Published in: Java
Expand |
Embed | Plain Text
package com.destiney.Prime; class Prime { { int x, y, c = 0; for( x = 2; x < 1000; x++ ) { if( x % 2 != 0 || x == 2 ) { for( y = 2; y <= x / 2; y++ ) { if( x % y == 0 ) { break; } } if( y > x / 2 ) { c++; } } } } }
Comments
Subscribe to comments
You need to login to post a comment.

Thanks works great!
This works great but I need one that uses arrays. Thanks anyway
This might help!!
/** * */ package main; import java.util.Arrays;
/** * @author Shri Krishan Yadav * This program find and displays prime numbers between 1 and a given number. * It doesn't include the number entered. */ public class PrimeNumbers {
}
import java.util.Scanner; public class Primes {
int n = sc.nextInt(); int x, y, c = 0; for( x = 2; x < n ; x++ ) { if( x % 2 != 0 || x == 2 ) { for( y = 2; y x / 2 ) { System.out.println( x ); c++; } } } System.out.println( "\nTotal: " + c );}
} //simple user input