« Home | What is Garbage Collection & Why is Garbage Collec... » | Public static void main (String args[]) » | Delete and Update values in MySql Using Java » | Insert values into table Using Java » | Program to Retrive values from Mysql Using Java » | Java Mysql Connectivity » | Program to Delete Files in a Given Directory » | Program to Write to a file » | Program to Rename Files in a given Directory » 

Saturday, March 11, 2006 

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();
}

}
}

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com