0% found this document useful (0 votes)
1 views29 pages

All Program

The document contains Java programs for various number classifications and patterns, including Armstrong, Palindrome, Perfect, Strong, Neon, Automorphic, Duck, Spy, Harshad, Disarium, Sunny, Prime, Composite, Twin Prime, Perfect Square, and Perfect Cube numbers. It also includes Fibonacci series generation and patterns like Hollow Square, Inverted Triangle, and Same Number Row. Each program includes a method to check the specific number type and a main method for user input.

Uploaded by

arnavchandra2323
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)
1 views29 pages

All Program

The document contains Java programs for various number classifications and patterns, including Armstrong, Palindrome, Perfect, Strong, Neon, Automorphic, Duck, Spy, Harshad, Disarium, Sunny, Prime, Composite, Twin Prime, Perfect Square, and Perfect Cube numbers. It also includes Fibonacci series generation and patterns like Hollow Square, Inverted Triangle, and Same Number Row. Each program includes a method to check the specific number type and a main method for user input.

Uploaded by

arnavchandra2323
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

PROGRAMS CLASS X (2026-27)

1. Armstrong Number
A number in which the sum of its digits raised to the power of the number of
digits is equal to the number itself.

package Numbers;

import [Link].*;

class Armstrong {

boolean isArmstrong(int n) {
int sum = 0;

for (int temp = n; temp != 0; temp /= 10) {


int digit = temp % 10;
sum += digit * digit * digit;
}

return sum == n;
}

void main() {

Scanner sc = new Scanner([Link]);


[Link]("Enter a number: ");

int num = [Link]();

if (isArmstrong(num))
[Link](num + " is an Armstrong number.");
else
[Link](num + " is NOT an Armstrong number.");

}
2. Palindrome Number
A number that remains the same when its digits are reversed.
package Numbers;

import [Link].*;

class Palindrome
{
//function to check palindrome
boolean isPalindrome(int n)
{
int rev = 0;
int d =0;
for (int temp =n ; temp>0; temp /= 10)
{
d = temp%10;
rev = rev *10 +d;
}
return rev == n;
}
//main method to create an object and input a number
void main()
{
Palindrome ob = new Palindrome();
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if ([Link](num))
[Link](num + " is a Palindrome.");
else
[Link](num + " is NOT a Palindrome.");
}

}
3. Perfect Number
A number whose sum of proper divisors (excluding itself) is equal to the
number.
package Numbers;

import [Link].*;

class PerfectNumber
{
boolean isPerfect(int n)
{
int sum = 0;

for (int i = 1; i < n; i++)


{
if (n % i == 0)
{
sum += i;
}
}
return sum == n;
}

void main() {

Scanner sc = new Scanner([Link]);


[Link]("Enter a number: ");

int num = [Link]();

if (isPerfect(num))
[Link](num + " is a Perfect number.");
else
[Link](num + " is NOT a Perfect number.");

}
4. Strong Number
A number in which the sum of the factorials of its digits is equal to the number.
package Numbers;

import [Link].*;
//NOTE: THIS IS ALSO CALLED AS krishnamur... number
class StrongNumber {
//Function to find factorial
int factorial(int n) {

int fact = 1;

for (int i = 1; i <= n; i++)


fact *= i;

return fact;

}
//Function to check if strong
boolean isStrong(int n) {

int temp = n, sum = 0;

for ( ; temp != 0; temp /= 10)


{
sum += factorial(temp % 10);
}
return sum == n;

}
//main method
void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();


if (isStrong(num))
[Link](num + " is a Strong number.");
else
[Link](num + " is NOT a Strong number.");

}
5. Neon Number
A number where the sum of digits of its square is equal to the number.
package Numbers;

import [Link].*;

class NeonNumber {

boolean isNeon(int n) {
int sum = 0;

for (int temp = n * n; temp != 0; temp /= 10)


sum += temp % 10;

return sum == n;
}

void main() {
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isNeon(num))
[Link](num + " is a Neon number.");
else
[Link](num + " is NOT a Neon number.");

}
6. Automorphic Number
A number whose square ends with the same digits as the number itself.
package Numbers;

import [Link].*;

class Automorphic {

boolean isAutomorphic(int n) {
int sq = n * n; //calculate square
int c = 1;//to store number of digits
for (int temp = n; temp != 0; temp /= 10)
{
c *= 10; //ye explain kar dunga abhi
}
return sq % c == n;
}

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isAutomorphic(num))
[Link](num + " is Automorphic.");
else
[Link](num + " is NOT Automorphic.");

}
7. Duck Number
A number that contains at least one zero but does not start with zero.
package Numbers;

import [Link].*;

class DuckNumber {

boolean isDuck(int n)
{
for (int temp = n; temp != 0; temp /= 10)
{
if (temp % 10 == 0)
{
return true;
}
}
return false;
}

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();


if (isDuck(num))
[Link](num + " is a Duck number.");
else
[Link](num + " is NOT a Duck number.");

}
8. Spy Number
A number in which the sum of digits is equal to the product of digits.
import [Link].*;

class SpyNumber
{
boolean isSpy(int n)
{
int sum = 0, product = 1;

for (int temp = n; temp != 0; temp /= 10)


{
sum += temp % 10;
product *= temp % 10;
}

return sum == product;


}
void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isSpy(num))
[Link](num + " is a Spy number.");
else
[Link](num + " is NOT a Spy number.");

}
9. Harshad (Niven) Number
A number that is divisible by the sum of its digits.
package Numbers;

import [Link].*;

class HarshadNumber {

boolean isHarshad(int n) {
int sum = 0;

for (int temp = n; temp != 0; temp /= 10)


{

sum += temp % 10;


}
return n % sum == 0;
}

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isHarshad(num))
[Link](num + " is a Harshad number.");
else
[Link](num + " is NOT a Harshad number.");

}
10. Disarium Number
A number where the sum of its digits powered with their respective positions is
equal to the number. (low chances)

package Numbers;

import [Link].*;
class DisariumNumber
{
//fucntion to check if it is a disarium number
boolean isDisarium(int n)
{
int d,sum = 0,c=0,temp = n;
//loop to find the number of digits
while (temp>0)
{
c++;
temp/=10;
}
temp = n;
//loop to raise the digit to the power of its place value
for (int i =c;i>0;i--)
{
d = temp%10; // extracts the last digit
sum +=[Link](d,i); //raise the power to its place value
temp/=10;// deletes the last digit
}
return sum==n;
}
//main function to create object and check for the number
void main()
{
Scanner sc = new Scanner ([Link]);
DisariumNumber ds = new DisariumNumber();
int n;
[Link]("Enter A number:");
n = [Link]();
if(isDisarium(n))
[Link](n+" is a disarium number");
else
[Link](n+" is not a disarium number");
}
}
11. Sunny Number
A number whose next number is a perfect square.
import [Link].*;

class SunnyNumber
{
//function to check sunny number
boolean isSunny(int n)
{

for (int i = 1; i * i <= (n+1); i++) // 1*1 <=9? yas 2*2? yas 3*3? yass 4*4?
no
{
if (i * i == (n+1)) //1*1 ==9? no 2*2 ==9? no 3*3 ==9? yass
{
return true;
}
}
return false;

}
//main method to input the number and check
void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isSunny(num))
[Link](num + " is a Sunny number.");
else
[Link](num + " is NOT a Sunny number.");
}

}
13. Prime Number
A number greater than 1 that has only two factors: 1 and itself.
package Numbers;

import [Link].*;

class PrimeNumber {

boolean isPrime(int n) {
int c =0;
for (int i = 1; i<= n; i++)
{
if (n % i == 0)
{
c++;
}
}
return c==2 ;

void main() {
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isPrime(num))
[Link](num + " is a Prime number.");
else
[Link](num + " is NOT a Prime number.");

}
14. Composite Number
A number that has more than two factors.
package Numbers;

import [Link].*;

class CompositeNumber {
//function to check composite number
boolean isComposite(int n)
{
int c =0;
for(int i =1; i<=n; i++)
{
if (n%i ==0)
c++;
}
return c!=2;
}
//main method to create object and input a number
void main()
{
CompositeNumber obj = new CompositeNumber();
Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if ([Link](num))
[Link](num + " is a Composite number.");
else
[Link](num + " is NOT a Composite number.");

}
}
15. Twin Prime Numbers
A pair of prime numbers whose difference is exactly 2.
package Numbers;

import [Link].*;

class TwinPrime {

boolean isPrime(int n) {

if (n < 2)
return false;

for (int i = 2; i * i <= n; i++)


if (n % i == 0)
return false;

return true;

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter first number : ");


int a = [Link]();
[Link]("Enter second number: ");
int b = [Link]();

if (isPrime(a)&&isPrime(b))
[Link](a + " and " + b + " are Twin Primes.");
else
[Link](a + " and " + b + " are NOT Twin Primes.");

}
17. Perfect Square Number
A number that is the square of an integer.
package Numbers;

import [Link].*;

class PerfectSquare {

boolean isPerfectSquare(int n) {

for (int i = 1; i * i <= n; i++)


if (i * i == n)
{
return true;
}
return false;

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isPerfectSquare(num))
[Link](num + " is a Perfect Square.");
else
[Link](num + " is NOT a Perfect Square.");

18. Perfect Cube Number


A number that is the cube of an integer.
package Numbers;
import [Link].*;

class PerfectCube {
//fucntion to check perfect cube
boolean isPerfectCube(int n) {

for (int i = 1; i * i * i <= n; i++)


if (i * i * i == n)
return true;

return false;

}
//main method
void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter a number: ");

int num = [Link]();

if (isPerfectCube(num))
[Link](num + " is a Perfect Cube.");
else
[Link](num + " is NOT a Perfect Cube.");
}

}
Fiboonacci series:
package Patterns;
import [Link].*;
class Fibonacci
{
//function to return the term of fibonaaci
void term(int n) {
int a = 0, b = 1, c;

for (int i = 1; i <= n; i++) {


[Link](a + " ");
c = a + b;
a = b;
b = c;
}
}
void main()
{
Scanner sc = new Scanner ([Link]);
[Link]("ENter the limit");
int n = [Link]();
term(n);
}
}

4. Hollow Square
*****
* *
* *
* *
*****

class HollowSquare {

void printHollow(int n) {

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= n; j++) {

if (i == 1 || i == n || j == 1 || j == n)
[Link]("*");
else
[Link](" ");

[Link]();
}

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter size: ");

int n = [Link]();

printHollow(n);

}
*****
****
***
**
*
import [Link].*;

class InvertedTriangle {
void printInverted(int n) {

for (int i = n; i >= 1; i--) {

for (int j = 1; j <= i; j++)


[Link]("*");

[Link]();

void main() {

Scanner sc = new Scanner([Link]);

[Link]("Enter rows: ");

int n = [Link]();

printInverted(n);

}
}Same Number Row Pattern
1
22
333
4444
import [Link].*;

class SameNumberRow {

void printPattern(int n) {

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= i; j++)


[Link](i);

[Link]();

void main() {

Scanner sc = new Scanner([Link]);


[Link]("Enter rows: ");

int n = [Link]();

printPattern(n);

You might also like