Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
a48eede8ad
commit
ee1a31b5e1
5 changed files with 103 additions and 0 deletions
27
OOP/Java/Lab/Week3/PrimeGen.java
Normal file
27
OOP/Java/Lab/Week3/PrimeGen.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
public class PrimeGen {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
System.out.println("Enter the numbers you want as the lower and upper limits of the prime number generator: ");
|
||||
int n = sc.nextInt();
|
||||
int m = sc.nextInt();
|
||||
|
||||
System.out.println("The Prime Numbers between " + n + " & " + m + " are:");
|
||||
|
||||
for(int i = n; i<=m; i++){
|
||||
int flag = 0;
|
||||
for(int j = 2; j<i; j++){
|
||||
if((i%j)==0){
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
|
||||
if(flag == 0){
|
||||
System.out.print(i+" ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue