Question: Write a Java program that includes predicates (functions which return a logical value) to find special integers called K-numbers . A positive integer X is

Write a Java program that includes predicates (functions which return a logical value) to find special integers called K-numbers. A positive integer X is a K-number if:

1. X is an odd integer, and

2. X is a square (X = N*N), and

3. X is symmetric (if the digits are reversed, the number is unchanged). A symmetric integer is called a palindrome.

Your program should include the following predicates:

a. boolean OddInt(long X): return value is true if X is an odd integer, and false otherwise.

b. boolean SquareInt(long X): return value is true if X is a perfect square, and false otherwise.

c. boolean SymmetricInt(long X): return value is true if X is symmetric, and false otherwise.

d. boolean KNumber(long X): return value is true if X is a K-number, and false otherwise. This function should be defined using the above three functions in the following logical rule:

KNumber(X) if OddInt(X) and SquareInt(X) and SymmetricInt(X)

In a Java program, the boolean datatype with values true and false can be used to represent logical variables.

Have your program receive two integer values N1 and N2 as command-line input. Then check all integers from N1 to N2 to find and display any K-numbers within that range.

Run your program for the following input ranges:

1. N1 = 1 N2 = 1,000

2. N1 = 1,000 N2 = 1,000,000

3. N1 = 1,000,000 N2 = 10,000,000

Can you find any larger K-Numbers?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!