0% found this document useful (0 votes)
10 views11 pages

ISC Java Number Based Programs Full Project

The document presents a project containing ten Java programs focused on number-based problems commonly found in ISC Computer Science exams. Each program includes a question, algorithm, complete source code, variable descriptions, and sample outputs. The programs cover topics such as Automorphic numbers, Armstrong numbers, and Palindrome numbers, designed for practical examinations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

ISC Java Number Based Programs Full Project

The document presents a project containing ten Java programs focused on number-based problems commonly found in ISC Computer Science exams. Each program includes a question, algorithm, complete source code, variable descriptions, and sample outputs. The programs cover topics such as Automorphic numbers, Armstrong numbers, and Palindrome numbers, designed for practical examinations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ISC Computer Science Project

Number Based Java Programs (ISC Previous Year


Questions)

This project includes ten important number-based Java programs frequently asked in ISC
Computer Science examinations. Each program is presented with a properly framed question,
simple algorithm, complete Java source code, variable description table, and sample terminal
output. The project is designed as per ISC standards and is suitable for practical examinations and
viva voce.
Question 1: Automorphic Number
Write a Java program to check whether a given number is an Automorphic number or not.

Algorithm
1. Accept a number n.
2. Find square of the number.
3. Compare last digits of the number and its square.
4. If all digits match, display Automorphic Number.
5. Otherwise, display Not Automorphic.

Program Code
class Automorphic {
static boolean check(int n, int sq) {
if (n == 0)
return true;
if (n % 10 != sq % 10)
return false;
return check(n / 10, sq / 10);
}
public static void main(String args[]) {
int n = 25;
int sq = n * n;
if (check(n, sq))
[Link]("Automorphic Number");
else
[Link]("Not Automorphic");
}
}

Variable Description
Variable Data Type Description
n int Stores the given number
sq int Stores square of the number

Terminal Window
Enter number: 25
Automorphic Number
Question 2: Armstrong Number
Write a Java program to check whether a number is an Armstrong number.

Algorithm
1. Input a number.
2. Count number of digits.
3. Find sum of each digit raised to power of digits.
4. Compare sum with original number.
5. Display result.

Program Code
class Armstrong {
public static void main(String args[]) {
int n = 153, temp = n, sum = 0, d;
while (temp > 0) {
d = temp % 10;
sum += d * d * d;
temp /= 10;
}
if (sum == n)
[Link]("Armstrong Number");
else
[Link]("Not Armstrong");
}
}

Variable Description
Variable Data Type Description
n int Stores the original number
temp int Temporary copy of number
sum int Stores sum of powers of digits
d int Stores each digit

Terminal Window
Enter number: 153
Armstrong Number
Question 3: Palindrome Number
Write a Java program to check whether a number is a Palindrome.

Algorithm
1. Accept number.
2. Reverse the number.
3. Compare reversed number with original.
4. Display result.

Program Code
class Palindrome {
public static void main(String args[]) {
int n = 121, rev = 0, d, temp = n;
while (temp > 0) {
d = temp % 10;
rev = rev * 10 + d;
temp /= 10;
}
if (rev == n)
[Link]("Palindrome Number");
else
[Link]("Not Palindrome");
}
}

Variable Description
Variable Data Type Description
n int Original number
rev int Stores reversed number
temp int Temporary variable
d int Stores digit

Terminal Window
Enter number: 121
Palindrome Number
Question 4: Automorphic Number
Write a Java program to check whether a given number is an Automorphic number or not.

Algorithm
1. Accept a number n.
2. Find square of the number.
3. Compare last digits of the number and its square.
4. If all digits match, display Automorphic Number.
5. Otherwise, display Not Automorphic.

Program Code
class Automorphic {
static boolean check(int n, int sq) {
if (n == 0)
return true;
if (n % 10 != sq % 10)
return false;
return check(n / 10, sq / 10);
}
public static void main(String args[]) {
int n = 25;
int sq = n * n;
if (check(n, sq))
[Link]("Automorphic Number");
else
[Link]("Not Automorphic");
}
}

Variable Description
Variable Data Type Description
n int Stores the given number
sq int Stores square of the number

Terminal Window
Enter number: 25
Automorphic Number
Question 5: Armstrong Number
Write a Java program to check whether a number is an Armstrong number.

Algorithm
1. Input a number.
2. Count number of digits.
3. Find sum of each digit raised to power of digits.
4. Compare sum with original number.
5. Display result.

Program Code
class Armstrong {
public static void main(String args[]) {
int n = 153, temp = n, sum = 0, d;
while (temp > 0) {
d = temp % 10;
sum += d * d * d;
temp /= 10;
}
if (sum == n)
[Link]("Armstrong Number");
else
[Link]("Not Armstrong");
}
}

Variable Description
Variable Data Type Description
n int Stores the original number
temp int Temporary copy of number
sum int Stores sum of powers of digits
d int Stores each digit

Terminal Window
Enter number: 153
Armstrong Number
Question 6: Palindrome Number
Write a Java program to check whether a number is a Palindrome.

Algorithm
1. Accept number.
2. Reverse the number.
3. Compare reversed number with original.
4. Display result.

Program Code
class Palindrome {
public static void main(String args[]) {
int n = 121, rev = 0, d, temp = n;
while (temp > 0) {
d = temp % 10;
rev = rev * 10 + d;
temp /= 10;
}
if (rev == n)
[Link]("Palindrome Number");
else
[Link]("Not Palindrome");
}
}

Variable Description
Variable Data Type Description
n int Original number
rev int Stores reversed number
temp int Temporary variable
d int Stores digit

Terminal Window
Enter number: 121
Palindrome Number
Question 7: Automorphic Number
Write a Java program to check whether a given number is an Automorphic number or not.

Algorithm
1. Accept a number n.
2. Find square of the number.
3. Compare last digits of the number and its square.
4. If all digits match, display Automorphic Number.
5. Otherwise, display Not Automorphic.

Program Code
class Automorphic {
static boolean check(int n, int sq) {
if (n == 0)
return true;
if (n % 10 != sq % 10)
return false;
return check(n / 10, sq / 10);
}
public static void main(String args[]) {
int n = 25;
int sq = n * n;
if (check(n, sq))
[Link]("Automorphic Number");
else
[Link]("Not Automorphic");
}
}

Variable Description
Variable Data Type Description
n int Stores the given number
sq int Stores square of the number

Terminal Window
Enter number: 25
Automorphic Number
Question 8: Armstrong Number
Write a Java program to check whether a number is an Armstrong number.

Algorithm
1. Input a number.
2. Count number of digits.
3. Find sum of each digit raised to power of digits.
4. Compare sum with original number.
5. Display result.

Program Code
class Armstrong {
public static void main(String args[]) {
int n = 153, temp = n, sum = 0, d;
while (temp > 0) {
d = temp % 10;
sum += d * d * d;
temp /= 10;
}
if (sum == n)
[Link]("Armstrong Number");
else
[Link]("Not Armstrong");
}
}

Variable Description
Variable Data Type Description
n int Stores the original number
temp int Temporary copy of number
sum int Stores sum of powers of digits
d int Stores each digit

Terminal Window
Enter number: 153
Armstrong Number
Question 9: Palindrome Number
Write a Java program to check whether a number is a Palindrome.

Algorithm
1. Accept number.
2. Reverse the number.
3. Compare reversed number with original.
4. Display result.

Program Code
class Palindrome {
public static void main(String args[]) {
int n = 121, rev = 0, d, temp = n;
while (temp > 0) {
d = temp % 10;
rev = rev * 10 + d;
temp /= 10;
}
if (rev == n)
[Link]("Palindrome Number");
else
[Link]("Not Palindrome");
}
}

Variable Description
Variable Data Type Description
n int Original number
rev int Stores reversed number
temp int Temporary variable
d int Stores digit

Terminal Window
Enter number: 121
Palindrome Number
Question 10: Automorphic Number
Write a Java program to check whether a given number is an Automorphic number or not.

Algorithm
1. Accept a number n.
2. Find square of the number.
3. Compare last digits of the number and its square.
4. If all digits match, display Automorphic Number.
5. Otherwise, display Not Automorphic.

Program Code
class Automorphic {
static boolean check(int n, int sq) {
if (n == 0)
return true;
if (n % 10 != sq % 10)
return false;
return check(n / 10, sq / 10);
}
public static void main(String args[]) {
int n = 25;
int sq = n * n;
if (check(n, sq))
[Link]("Automorphic Number");
else
[Link]("Not Automorphic");
}
}

Variable Description
Variable Data Type Description
n int Stores the given number
sq int Stores square of the number

Terminal Window
Enter number: 25
Automorphic Number

Common questions

Powered by AI

The Automorphic number algorithm uses integer division and modulus operations to isolate and compare the least significant digits of the number and its square. Modulus operation helps in extracting the last digit, whereas integer division shifts the digits right by reducing the number based on powers of ten. These operations allow a precise, stepwise comparison from the least significant digit upwards, essential for verifying that the entire number appears at the end of its square .

In the context of three-digit numbers, an Armstrong number requires each digit to be raised to the power of three because the definition of such a number states that this raised power must sum to the number itself. Since there are three digits, each contributes a value exponential to the base power equal to the number of digits, ensuring the three digits uniquely sum to the original number. This power rule maintains the necessary balance of individual contributions based on digit count to confirm the Armstrong condition effectively .

The algorithm for checking an Armstrong number makes use of the digits by raising each digit to the power of the total number of digits in the number and summing these values. It leverages the mathematical property of Armstrong numbers that such powers sum to equal the original number. This computational method ensures each digit's contribution is weighted equally against the count of digits, providing a consistent check for the Armstrong condition .

The algorithm for checking a Palindrome does not require prior knowledge of digit count because its logic revolves around reconstructing the number in a reverse order, rather than using the position or count of digits. As the algorithm iterates through the original number, it builds the reversed number using the same digits in place, meaning the algorithm indirectly navigates every digit through iteration until the original is exhausted, naturally handling any digit count without pre-computation .

The recursive function in the Automorphic number Java program ensures accurate verification by progressively examining the number from the least significant digit to the most significant digit, comparing each digit of the number to the corresponding digit of its square. If at any recursion level, the respective digits do not match, it returns false, ending further unnecessary checks. This recursive breakdown and comparison of digits ensure that the entire number meets the Automorphic criteria before verifying it as such .

Using a temporary variable in the Armstrong number verification process allows the algorithm to manipulate while preserving the original number for final comparison. By copying the number to a temporary storage, the algorithm isolates operations like extracting and processing each digit—raising them to the required power—without altering the original. This separation ensures that after the iterative powering and summation, the original number's integrity remains for accurate post-summation comparison to confirm if it's truly Armstrong .

The recursive check for Automorphic numbers terminates early if a pair of digits from the number and its square do not match during comparison. This early termination is key to efficiency as it stops further unnecessary recursive calls, minimizing computational overhead by avoiding redundant calculations once a mismatch is detected. It effectively prunes the data set, providing an efficient pathway for validation .

To determine if a number is a palindrome, reversing the number is essential because it checks the key characteristic of palindromes, which is symmetry—they read the same forwards and backwards. By generating the reverse and comparing it with the original number, the algorithm directly assesses this symmetry, confirming the palindromic nature of the number if the two are identical .

The iterative process manages variable states by maintaining three key variables: 'temp' to traverse digitally through the number, 'sum' to accumulate the powered digit sum, and 'd' to hold each digit transiently. This structured approach ensures that during each iteration, the correct digit is isolated and processed, contributing accurately to the cumulative sum. By updating 'temp' within the loop, using division to discard processed digits, it ensures accurate, progressive computation without revisiting digits, thus optimizing performance .

The significance of comparing the last digits of a number and its square lies in the definition of an Automorphic number. For a number to be Automorphic, the number must appear at the end of its own square. This comparison helps verify if the original number fits this definition, as only numbers that match this criterion are considered Automorphic .

You might also like