Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gunashekar
answer it soon
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number or not


Advertisement
View Answers

April 29, 2011 at 11:50 AM


import java.util.*;

class PrimeFactors {
        static boolean isPrime(long number) {
                boolean isPrime = false;
                int i = (int) Math.ceil(Math.sqrt(number));
                while (i > 1) {
                        if ((number != i) && (number % i == 0)) {
                                isPrime = false;
                                break;
                        } else if (!isPrime)
                                isPrime = true;
                        --i;
                }
                return isPrime;
        }

        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                long n = input.nextLong();
                 long sum=0;
        System.out.print("Sum of Prime Factors of " + n + " is: ");
        for (long i = 2; i <= n / i; i++) {
            while (n % i == 0) {
                sum+=i;
                n = n / i;
            }
        }
         if (n > 1){
             sum=sum+n;
         }
        else {    
             sum=sum+0;
        }
         System.out.print(sum);
         System.out.println();
         if(isPrime(sum)){
            System.out.println("Sum of prime factors of a number is a prime number");
         }
         else{
             System.out.println("Not Prime!");
         }
        }
}


Related Tutorials/Questions & Answers:
answer it soon
answer it soon  write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number
pls give me answer ae soon as possible - Ajax
pls give me answer ae soon as possible  i m writing code of ajax technology ...but it is not working pls check it n give me response quickly... give me quick response!!! thanks & regards shashank gupta
Advertisements
Reply me soon.........
Reply me soon.........  Any body plzz help.....how to get d checked details from previous page to current page and den insert into table
plz plz rply as soon as possible
plz plz rply as soon as possible  by using c programs * * * * * s s s s s * s s o s s s s s s s s s s s s s s s s s s s s s s s
java.please answer this...
java.please answer this...   Q1).How we can write a complete JAVA program that computes the following summation formulas..? ??_(i=1)^n????i^2=?? (n^(2 ) ??(n+1)??^2)/4
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It... be send reply soon. Thanks & Regards, N.Ramesh
need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less
Answer for SCJP Module-1 Question-13
Answer for SCJP Module-1 Question-13  The Answer for SCJP Module-1 Question-13 is missing , I think the answer is option '1', Correct me if I am wrong
pls answer the Trangle pattern
pls answer the Trangle pattern    a b c d e b c d e c d e d e e Please answer and give the code for above triangle
Urgent Answer Req
Urgent Answer Req  how to view the file content which is at client side from jsp in java
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please answer me
please answer me  iam using html in select tag.in this one option i selected and that option data will be display in table.And use servlet with html and how to retrieve the data from data base
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.  For my website,As soon as the user is able to succesfully login, a Testimonial FORM appears in the same page. How to do. Please Help
share your answer to this question
share your answer to this question  i need to know what is the TELERIK CONTROL? what is the map suite? what is dunda chart? Also i have to know what are the websites available which give infor regarding this. Let me know how
pls answer these question
pls answer these question  Write a program that prompts the user to input the length and width of a rectangle. Then calculate and prints the rectangle??s area and perimeter.   import java.io.*; class rectangle
Is the answer 35, 35?
Is the answer 35, 35?  int a = 5; int b = 7; int num = 35; while (a < b) { System.out.println(?My age is ? + num); a = a + 1; }   Hello Friend, class Check{ public static void main(String[] args
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
java program...need help as soon as possible!!! - Java Beginners
java program...need help as soon as possible!!!  Modify the Lexer (15 points): 1. Use a command line argument for the input file for processing tokens ? do not use simple.x 2. Recognize the new tokens > void float
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
Two compilation errors.Can anyone help soon. - Java Beginners
Two compilation errors.Can anyone help soon.  a program called Date.java to perform error-checking on the initial values for instance fields month, day and year. Also, provide a method nextDay() to increment the day by one
please send me the answer - JDBC
please send me the answer -difference between DriverManager and DataDourse   what is Datasourse? What r the advantages? what is the difference between DriverManager and DataDourse
Please answer me - JSP-Servlet
Please answer me  Hello Guys, this is the third time I'm sending this question. But I've not got the right answer from you. The again is: I need java servlet or jsp codes that I can use to insert and retrieve image from MSSQL
Plz send me answer quckly
Plz send me answer quckly  Respected Sir, myself is pavan shrivastava.i want ask a question that is ( we can't create object of interface then how would possible to create object
answer this qs in 5 mins plss
answer this qs in 5 mins plss  Create an Web Application, which allows a user to search a book as follows: Based on ISBN code, if he is aware of the code (or) Based on the Book Categories The results of the search has
i cNT GET ANSWER FOR THIS QUESTION
i cNT GET ANSWER FOR THIS QUESTION  The roots of the quadratic equation ax2+bx+c=0, aï??¹0 are given by the following formula: x=(-b?±â?š(b^2-4ac))/2a In this formula. The term b2-4ac is called
What is the answer and how the program work?
What is the answer and how the program work?  public class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Advertisements
 

 

 

DMCA.com