PRIME FACTORS OF ALL NON-PRIMES BELOW 500
/*TO PRINT THE PRIME FACTORS OF ALL NON-PRIMES BELOW 500*/
/*AUTHOR:SIVAPHANINDRA.VEMURI*/
import java.io.*; /*IMPORTING SECTION*/
class Task1e2 /* DECLARING A CLASS NAMED Task1e2*/
{
public static void main(String args[])throws IOException /*MAIN METHOD THROWING IOEXCEPTION*/
{
int i,j=0;
int a[]=new int [500]; /*ALLOCATING MEMORY FOR ARRAY A OF 500 SIZE*/
String fp; /* CREATING AN OBJECT FOR STRING*/
BufferedReader br=new BufferedReader (new FileReader("non-primes.txt"));
while((fp=br.readLine())!=null)
{
a[j]=Integer.parseInt(fp);
j++;
fp=br.readLine();
}
br.close();
PrintStream ps= new PrintStream(new FileOutputStream ("non-primes.txt"),true); /*CREATING AN OBJECT FOR PRINT STRAM*/
for(i=0;i {
ps.print(a[i]+":");
int prmfact = 2;
while (a[i] > 1)
{
if (a[i] % prmfact == 0)
{
ps.print(prmfact+"*"); /*PRINITING THE PRIMEFACTOR TO THE FILE*/
a[i] = a[i] / prmfact;
}
else
{
prmfact = prmfact + 1;
}
if (prmfact * prmfact > a[i])
{
ps.print(a[i]+" ");
ps.println();
break;
}
}
ps.println();
}
}
}
/*AUTHOR:SIVAPHANINDRA.VEMURI*/
import java.io.*; /*IMPORTING SECTION*/
class Task1e2 /* DECLARING A CLASS NAMED Task1e2*/
{
public static void main(String args[])throws IOException /*MAIN METHOD THROWING IOEXCEPTION*/
{
int i,j=0;
int a[]=new int [500]; /*ALLOCATING MEMORY FOR ARRAY A OF 500 SIZE*/
String fp; /* CREATING AN OBJECT FOR STRING*/
BufferedReader br=new BufferedReader (new FileReader("non-primes.txt"));
while((fp=br.readLine())!=null)
{
a[j]=Integer.parseInt(fp);
j++;
fp=br.readLine();
}
br.close();
PrintStream ps= new PrintStream(new FileOutputStream ("non-primes.txt"),true); /*CREATING AN OBJECT FOR PRINT STRAM*/
for(i=0;i
ps.print(a[i]+":");
int prmfact = 2;
while (a[i] > 1)
{
if (a[i] % prmfact == 0)
{
ps.print(prmfact+"*"); /*PRINITING THE PRIMEFACTOR TO THE FILE*/
a[i] = a[i] / prmfact;
}
else
{
prmfact = prmfact + 1;
}
if (prmfact * prmfact > a[i])
{
ps.print(a[i]+" ");
ps.println();
break;
}
}
ps.println();
}
}
}