Practice Program Assignment 3
Practice Program Assignment 3
1. A Smith number is a composite number, whose sum of the digits is equal to the sum
of its prime factors. For example: 4, 22, 27, 58, 85, 94, 121 ………. are Smith numbers.
Write a program in Java to enter a number and check whether it is a Smith number
or not.
2. A Goldbach number is a positive even integer that can be expressed as the sum of
two odd primes. It is to be noted that all even integer numbers greater than 4 are
Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, ‘6’ has one odd prime pair ‘3’ and ‘3’. Similarly, ‘10’ has two odd prime pairs,
i.e. ‘3’ and ‘7’, ‘5’ and ‘5’.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the
odd prime pairs whose sum is equal to the number 'N'.
Test your program with the following data and some random data:
Example 1 Example 2
INPUT: INPUT:
N = 14 N = 30
OUTPUT: OUTPUT:
PRIME PAIRS ARE: PRIME PAIRS ARE:
3, 11 7, 23
7, 7 11, 19
13, 17
3. Input a sentence from the user and count the number of times, the words “an” and
“and” are present in the sentence. Design a class Frequency using the description
given below:
Data Members
Member functions
Specify class Frequency giving details of the constructor(), void accept(String), void
checkand freq() and void display(). Also define the main function to create an object
and call methods accordingly to enable the task.