0% found this document useful (0 votes)
6 views3 pages

Special_Numbers_ICSE_Java_Expanded

The document provides definitions and Java programs for various special numbers in programming, including Armstrong, Palindrome, Automorphic, Abundant, and Circular Prime numbers. Each section includes a brief explanation of the number type, examples, and corresponding Java code to determine if a given number fits the criteria. Additionally, it reiterates the definition of Armstrong numbers specifically for three digits with a sample program.

Uploaded by

bhaskarsingh8330
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)
6 views3 pages

Special_Numbers_ICSE_Java_Expanded

The document provides definitions and Java programs for various special numbers in programming, including Armstrong, Palindrome, Automorphic, Abundant, and Circular Prime numbers. Each section includes a brief explanation of the number type, examples, and corresponding Java code to determine if a given number fits the criteria. Additionally, it reiterates the definition of Armstrong numbers specifically for three digits with a sample program.

Uploaded by

bhaskarsingh8330
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
You are on page 1/ 3

Special Numbers in Programming - ICSE Java Reference

Armstrong Number
Definition: A number equal to the sum of its digits each raised to the power of the number of digits.
Example(s): 153 -> 1^3 + 5^3 + 3^3 = 153

Java Program:
import java.util.Scanner;
public class Armstrong {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int temp = num, sum = 0;
while (temp > 0) {
int d = temp % 10;
sum += d * d * d;
temp /= 10;
}
if (sum == num)
System.out.println("Armstrong");
else
System.out.println("Not Armstrong");
}
}

Palindrome Number
Definition: A number that reads the same backward as forward.
Example(s): 121, 1331, 12321

Java Program:
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int temp = num, rev = 0;
while (temp > 0) {
rev = rev * 10 + temp % 10;
temp /= 10;
}
if (rev == num)
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}

Automorphic Number
Definition: A number whose square ends with the number itself.
Example(s): 76 -> 76^2 = 5776; ends with 76
Special Numbers in Programming - ICSE Java Reference

Java Program:
import java.util.Scanner;
public class Automorphic {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int sq = num * num;
int digits = (int)Math.log10(num) + 1;
int mod = (int)Math.pow(10, digits);
if (sq % mod == num)
System.out.println("Automorphic");
else
System.out.println("Not Automorphic");
}
}

Abundant Number
Definition: A number for which the sum of its proper divisors is greater than the number itself.
Example(s): 12 -> 1 + 2 + 3 + 4 + 6 = 16 > 12

Java Program:
import java.util.Scanner;
public class Abundant {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt(), sum = 0;
for (int i = 1; i < num; i++) {
if (num % i == 0) sum += i;
}
if (sum > num)
System.out.println("Abundant");
else
System.out.println("Not Abundant");
}
}

Circular Prime Number


Definition: A prime number that remains prime under all rotations of its digits.
Example(s): 197 -> 197, 971, 719 -> all prime

Java Program:
import java.util.Scanner;
public class CircularPrime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt(), temp = num;
int digits = 0;
while (temp > 0) {
digits++;
temp /= 10;
Special Numbers in Programming - ICSE Java Reference

}
int powTen = (int)Math.pow(10, digits - 1);
int n = num;
boolean isCircularPrime = true;
for (int i = 0; i < digits; i++) {
if (!isPrime(n)) {
isCircularPrime = false;
break;
}
int lastDigit = n % 10;
n = (lastDigit * powTen) + (n / 10);
}
if (isCircularPrime)
System.out.println("Circular Prime");
else
System.out.println("Not Circular Prime");
}

static boolean isPrime(int x) {


if (x < 2) return false;
for (int i = 2; i <= x / 2; i++)
if (x % i == 0) return false;
return true;
}
}

Armstrong Number (3 digits)


Definition: A number equal to the sum of the cubes of its digits.
Example(s): 153 -> 1^3 + 5^3 + 3^3 = 153

Java Program:
import java.util.Scanner;
public class ArmstrongSimple {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt(), temp = num, sum = 0;
while (temp > 0) {
int d = temp % 10;
sum += d * d * d;
temp /= 10;
}
if (sum == num)
System.out.println("Armstrong");
else
System.out.println("Not Armstrong");
}
}

You might also like