« Home | PRIME FACTORS OF ALL NON-PRIMES BELOW 500 » | 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 

PRINTING THE NON-PRIMES

//PROGRAM FOR PRINTING THE NON-PRIMES INTO A FILE
//AUTHOR:SIVAPHANINDRA.VEMURI

import java.io.*; /*IMPORTING SECTION*/
class Task1e1 /* DECLARING A CLASS NAMED Task1e1*/
{
public static void main(String args[]) /*MAIN FUNCTION*/
{
FileOutputStream file_out=null; /* CREATING STREAMS FOR DIRECTING IT TO THE OUTPUT FILE*/
PrintStream pno=null;
try{
file_out=new FileOutputStream("non-primes.txt",false);
pno = new PrintStream(file_out,true);
}catch(FileNotFoundException e){ /* TO CATCH EXCEPTIONS */
System.out.println();
return;
}
catch(IOException e){
System.out.println("IOEXCEPTION");
return;
}
int num=2;
do
{
for(int i=2;i <num;i++)
{
if((num%i)==0) /*CHECKING FOR NON PRIMES*/
{

pno.println(num); /*FOR WRITING TO THE FILE */
pno.println();
break;
}
}
num++;
}while(num!=500); /*TO PRINT ALL THE NON PRIMES BETWEEN 1-500*/
}
}

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