-
Notifications
You must be signed in to change notification settings - Fork 3
/
prime_txt.java
39 lines (35 loc) · 952 Bytes
/
prime_txt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.*;
public class prime_txt {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int num = sc.nextInt();
try
{
FileWriter fw = new FileWriter("prime_int.txt");
System.out.println("Printing all prime numbers");
for (int i=1; i<num; i++)
{
int count =0;
for(int j=2; j<i; j++)
{
if (i%j == 0)
count= count +1;
}
if(count ==0)
{
String s = String.valueOf(i);
fw.write(s+" ");
}
}
fw.close();
sc.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}