3 Replies - 335 Views - Last Post: 27 February 2011 - 03:39 AM Rate Topic: -----

#1 njabulo.f.msomi  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 09

Download the attachment to view problem

Posted 22 February 2011 - 10:59 AM

/**
 * @(#)Sophie.java
 *
 *
 * @author 
 * @version 1.00 2011/2/17
 */
import java.util.*;
public class Sophie {
        
    /**
     * Creates a new instance of <code>Sophie</code>.
     */
    public Sophie() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        
        
        
        Scanner sc = new Scanner(System.in);
       
       int t = sc.nextInt();
       String output="";
       if(t>=1 &&t<=20){
       	
       	 for(int i=0;i<t;i++){
       	  int count=0;
       	  int n=sc.nextInt();
       	  if(n>=1 && n<=10000){
       	  	
       	  	 for(int j=2;j<=n;j++){
       	  	 	if(isPrime(j)&&isPrime((2*j)+1)){
       	  	 		count++;
       	  	 	}
       	  	 
       	  	 }
       	  	
       	  	 output+="Case #" +(i+1)+": " + count+"\n";
       	  	
       	  }
       	  else{
       	  	
       	  	 return;
       	  }
       	 	
       	 }
       	
       	
        } 
       	else{
       		return;
       	}
        
        System.out.println();
        System.out.println(output);
        
    }
    
 public static boolean isPrime(int n){
    	if(n==0){
    		return false;
    	}
    	
    	for(int i=2;i<=n/2;i++){
    		if(n%i==0){
    			return false;
    		}
    	}
    	return true;
    }
}


// Attached File  1b.pdf (49.18K)
Number of downloads: 41

This post has been edited by macosxnerd101: 22 February 2011 - 11:04 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Download the attachment to view problem

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10185
  • View blog
  • Posts: 37,599
  • Joined: 27-December 08

Re: Download the attachment to view problem

Posted 22 February 2011 - 11:05 AM

Please post the errors in the body of your thread, not as an attachment.
Was This Post Helpful? 0
  • +
  • -

#3 shintetsu_80  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 105
  • Joined: 01-July 08

Re: Download the attachment to view problem

Posted 22 February 2011 - 11:11 AM

Does this sound like a potential virus to anyone else???
Was This Post Helpful? 0
  • +
  • -

#4 njabulo.f.msomi  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 09

Re: Download the attachment to view problem

Posted 27 February 2011 - 03:39 AM

We all learn by the previous mistakes.Thank you macosxnerd101

This post has been edited by njabulo.f.msomi: 27 February 2011 - 03:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1