All pastes #504624 Raw Edit

Something

public text v1 · immutable
·published 2007-05-23 05:20 UTC
rendered paste body
import java.io.*;
import java.util.Scanner;

class Primes{
   public static void main(String[] args){
      Scanner sc;
      int number,temp=-1,testr;
      if(args.length==0){
         Usage();
         return;
      }
      for(int i=0;i<args.length;i++){
         try{
            sc = new Scanner(new File(args[i]));
         }catch(FileNotFoundException e){
            Usage();
            continue;
         }
         while(sc.hasNextLine()){
            while(temp<0){
               if(sc.hasNextInt()){
                  temp=sc.nextInt();
               }
            }
         }
         number=temp;
         testr=testPrime(number);
         if(testr==1) System.out.println(number+" is prime.");
         if(testr>1) System.out.println(number+"is divisable by "+testr);
         if(testr==0) System.out.println("1 is neither prime nor copmposite");
      }
   }

static int testPrime(int n){
   int temp,ind=1;
   if(n==1) return 0;
   for(int i=2;i*i<n;i++){
      temp=n%i;
      if(temp==0){
         ind=temp;
         return ind;
      }
   }
   return ind;
}
static void Usage(){
   System.out.println("Usage: java Primes input_file");
}
}