Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago