0% found this document useful (0 votes)
2 views20 pages

Final Computer Project Class IX

The document contains a series of Java programs that check various properties of numbers, including whether they are prime, perfect, abundant, Armstrong, palindrome, automorphic, deficient, disarium, duck, evil, happy, Harshad, Kapriker, Krishnamurti, lead, lucky, narcissistic, neon, pronic, and spy numbers. Each program prompts the user to input a number and then evaluates it based on the specific criteria for that number type. The code snippets include necessary imports, class definitions, and logic to perform the calculations and display the results.

Uploaded by

santwanabh
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)
2 views20 pages

Final Computer Project Class IX

The document contains a series of Java programs that check various properties of numbers, including whether they are prime, perfect, abundant, Armstrong, palindrome, automorphic, deficient, disarium, duck, evil, happy, Harshad, Kapriker, Krishnamurti, lead, lucky, narcissistic, neon, pronic, and spy numbers. Each program prompts the user to input a number and then evaluates it based on the specific criteria for that number type. The code snippets include necessary imports, class definitions, and logic to perform the calculations and display the results.

Uploaded by

santwanabh
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/ 20

PROGRAM 1:- WRITE A PROGRAM TO ACCEPT A

NUMBER AND CHECK IT IS A PRIME NUMBER OR NOT

import java.util.*;
class primenumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
System.out.println(n+“ is a Prime Number”);
else
System.out.println(n+“ is not a Prime Number”);
}
}
PROGRAM 2:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A PERFECT NUMBER OR
NOT

import java.util.*;
class perfectnumber
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int n=sc.nextInt();
int c=0;
for (int i=1;i<=n;i++)
{
if(n%i==0)
c=c+i;
}
if (c==n)
System.out.println(n+“ is a Perfect number”);
else
System.out.println(n+” is not a Perfect number”);
}
}
WRITE A PROGRAM TO INPUT A NUMBER AND CHECK
IT IS A ABUNDANT NUMBER OR NOT
import java.util.*;
class abundantnumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c=c+i;
}
if(c>n)
System.out.println(n+“ is an Abundant number”);
else
System.out.println(n+“ is not an Abundant number”);
}
}
PROGRAM 4:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND DISPLAY THAT IT IS AN ARMSTRONG
NUMBER OR NOT.
import java.util.*;
class armstrongnumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int r=0,s=0,k=n;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(k==s)
System.out.println(k+"is an armstrong number");
else
System.out.println(k+"is not an armstrong number");
}
}
PROGRAM 5:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND DISPLAY IT IS A PALINODROME
NUMBER OR NOT.
import java.util.*;
class palinodromenumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int r=0,rev=0,k=n;
while(n>0)
{
r=n%10;
rev=(rev*10)+r;
n=n/10;
}
if(rev==k)
System.out.println(k+"is a palinodrome number");
else
System.out.println(k+"is not a palinodrome number");
}
}
PROGRAM 6:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND DISPLAY IT IS A AUTOMORPHIC
NUMBER OR NOT.
import java.util.*;
class automorphicnumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int sq=n*n;
int c=0,k=n;
while(n>0)
{
c++;
n=n/10;
}
int I=(int)(sq%Math.pow(10,c));
if(l==sq)
System.out.println(k+" is an automorphic number");
else
System.out.println(k+" is not an automorphic number");
}
}
PROGRAM 7:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A DEFICIENT NUMBER OR
NOT.
import java.util.*;
class deficientnumber
(
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int s=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
s=s+i;
}
if(c<n)
System.out.println(n+" is a Deficient number");
else
System.out.println(n+" is not a Deficient number");
}
}
PROGRAM 8:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A DISARIUM NUMBER OR
NOT
import java.util.*;
class disariumnumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int k=n,r=0,c=0,z=n,s=0;
while(n>0)
{
c++;
n=n/10;
}
while(k>0)
{
r=k%10;
s=s+(int)Math.pow(r,c);
c--;
k=k/10;
}
if(s==z)
System.out.println(z+" is a Disarium number");
else
System.out.println(z+" is not a Disarium number");
}
}
PROGRAM 9:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A DUCK NUMBER OR NOT.
import java.util.*;
class ducknumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int p=1,r=0,k=n;
while(n>0)
{
r=n%10;
p=p*r;
n=n/10;
}
if(p==0)
System.out.println(k+" is a Duck number");
else
System.out.println(k+" is not a Duck number”);
}
}
PROGRAM 10:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A EVIL NUMBER OR NOT
import java.util.*;
class evilnumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int n=sc.next Int();
int r=0,c=0,k=n;
while(n>0)
{
r=n%2;
if(r==1)
c++;
n=n/2;
}
if(c%2==0)
System.out.println(k+“ is an Evil number”);
else
System.out.println(k+“ is not an Evil number”);
}
}
PROGRAM 11:- WRITE A PROGRAM TO ACCEPT A NO
AND CHECK IT IS A HAPPY NUMBER OR NOT:-
import java.util.*;
class happynumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int n=sc.nextInt();
int r=0,k=0,sum=n;
while(sum>9)
{
k=sum;
sum=0;
while(k>0)
{
r=k%10;
sum=sum+(r*r);
k=k/10;
}
}
if(sum==1)
System.out.println(n+“ is a Happy Number”);
else
System.out.println(n+“ is an not a Happy Number’’);
}
}
PROGRAM 12:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A HARSHAD NUMBER OR
NOT
import java.util.*;
class harshadnumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int n=sc.nextInt();
int r=0,s=0,k=n;
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
if(k%s==0)
System.out.println(k+“ is a Harshad number”);
else
System.out.println(k+“ is not a Harshad number”);
}
}
PROGRAM 13:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A KAPRIKER NUMBER OR
NOT
import java.util.*;
class kaprikernumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System. in);
System.out.println("Enter a number");
int n=sc.nextInt();
int sq=n*n;
int c=0,k=sq;
while(sq>0)
{
c++;
sq=sq/10;
}
int d=c/2;
int z=(int)Math.pow(10,d);
int f=k/z;
int l=k%z;
int s=f+l;
if (n==s)
System.out.println(n+" is a Kapriker number");
else
System.out.println (n+" is not a Kapriker number");
}
}
PROGRAM 14:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS KRISHNAMURTI NUMBER
OR NOT
import java.util.*;
{
class krishnamurtinumber
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.next Int();
int r=0,f=1,s=0,k=n;
while(n>0)
{
r=n%10;
f=1;
for(int i=1;<=r,i++)
{
f=f*i;
}
n=n/10;
s=s+f;
}
if(s==k)
System.out.println(k+" is a Krishna murti number");
else
System.out.println(k+“ is not a Krishna murti number");
}
}
PROGRAM 15:- WRITE A PROGRAM TO ACCEPT A
NUMBER AND CHECK IT IS A LEAD NUMBER OR NOT
import java.util.*;
class leadnumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.printin("Enter a number");
int n=sc.nextInt();
int r=0,a=0,b=0,k=n;
while(n>0)
{
r=n%10;
if(r%2==0)
a=a+r;
else
b=b+r;
n=n/10;
}
if(a==b)
System.out.println (k+" is a Lead number");
else
System.out.println(k+" is not a Lead number");
}
}
PROGRAM 16:- WRITE A PROGRAM TO INPUT A NUMBER,
CHECK AND PRINT IT IS A LUCKY NUMBER OR NOT
import java.util.*;
class luckynumber
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int r=0,count=0;
for(int i=0;i<=9;i++)
{
int k=n;
count=0;
while(k>0)
{
r=(k%10);
if(r==i)
count++;
k=(k/10);
}
if(count>1)
break;
}
if(count>1)
System.out.println(n+" is not a lucky number");
else
System.out.println(n+" is a lucky number");
}
}
PROGRAM 17:- WRITE A PROGRAM TO INPUT A NUMBER,
CHECK AND PRINT IT IS A NARCISSISTIC NUMBER OR NOT
import java.util.*;
class narcissticnumber
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int c=0,s=0,r=0,k=n,z=n;
while(n>0)
{
c++;
n=n/10;
}
while(k>0)
{
r=k%10;
s=s+(int)Math.pow(r,c);
k=k/10;
}
if(z==s)
System.out.println(s+" is a Narcissistic Number");
else
System.out.println(s+" is not a Narcissistic Number");
}
}
PROGRAM 18:- WRITE A PROGRAM TO INPUT A NUMBER,
CHECK AND PRINT IT IS A NEON NUMBER OR NOT
import java.util.*;
class neonnumber
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int sq=n*n;
int r=0,s=0;
while(sq>0)
{
r=sq%10;
s=s+r;
sq=sq/10;
}
if(n==s)
System.out.println(n+" is a Neon Number");
else
System.out.println(n+" is not a Neon Number");
}
}
PROGRAM 19:- WRITE A PROGRAM TO ENTER A NUMBER,
CHECK AND PRINT IT IS A PRONIC NUMBER OR NOT
import java.util.*;
class pronicnumber
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int sq=(int)Math.sqrt(n);
int p=sq*(sq+1);
if(p==n)
System.out.println(n+" is a Pronic Number");
else
System.out.println(n+" is a not Pronic Number");
}
}
PROGRAM 20:- WRITE A PROGRAM TO INPUT A
NUMBER, CHECK AND PRINT IT IS A SPY NUMBER OR
NOT
import java.util.*;
class spynumber
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int s=0,r=0,m=1,k=n;
while(n>0)
{
r=n%10;
s=s+r;
m=m*r;
n=n/10;
}
if(s==m)
System.out.println(k+" is a Spy Number");
else
System.out.println(k+" is not a Spy Number");
}
}

You might also like