JAVA

PART -A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

1

 
  
 
 1. Write a Java program to display only those multi-digit prime numbers between a given range whose digit sum is prime. Display the prime number and its digit sum side by side. Read the value for the range using readLine() method of BufferedReader class.
Sample output:
If range is; m = 20, n=50
Prime number Sum of digits
23 -5
29-11
41-5
43-7
47-11
PROGRAM:

  import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
    public class SumandCheckp1{    

static void readRange(){
int m ,n,i;
try{
    BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
 System.out.println("Enter Start Range M: ");
        m = Integer.parseInt(reader.readLine());
      System.out.println("Enter End Range N: ");
        n = Integer.parseInt(reader.readLine());

    for (i=m;i< n;i++){

    checkPrime(i); 
    }
}catch(Exception e){}
}

    static void checkPrime(int value)
{  
      int i,m=0,flag=0,primetemp=0;
       int sum=0; 
            
        int temp=value;  
           
             while(temp>0)
           {
               sum=sum+temp%10;
                temp=temp/10;
           }
         
        primetemp=value; 
  
      m=primetemp/2;      
      if(primetemp==0||primetemp==1)
     {  
            flag=0;
         // System.out.println(n+" is not prime number");      
      }
    else
     {  
       for(i=2;i<=m;i++){      
        if(primetemp%i==0){      
            // System.out.println(n+" is not prime number");      
              flag=1; 
      
         break;      
        }      
       }      

       if(flag==0)  {
         System.out.println(value+" = "+sum+" ");
        }   
      } 
    }  
     public static void main(String args[]){    
                    readRange();
    }    
    }