Sei sulla pagina 1di 17

COMPUTER PROJECT

1) import java.util.Scanner;
public class krishnamoorthy
{
public void krishnamoorthy()
{
Scanner in=new Scanner (System.in);
int num= in.nextInt();
System.out.println("Enter the number to be checked");
int num1=num;
int tot=0;
while(num1 != 0)
{
int b=num1%10;
tot=tot+fact(b);
num1=num1/10;
}
if (tot==num)
System.out.println("The given number is a Krishnamoorthy
number");
else
System.out.println("The given number is not a Krishnamoorthy
number");
}
int fact(int x)
{
int i,p=1;
for(i=x;i>=1;i--)
p=p*i;
return p;
}
}
2) public class primefactorize
{
public void primefactorize(int n)
{
while(n%2==0)
{
System.out.print("2"+" ");
n=n/2;
}
for(int i=3; i<=n/2; i+=2)
{
while(n%i == 0)
{
System.out.print(i + " ");
n =n/i;
}
}
if (n > 2)
System.out.print(n);
}
}

3) import java.util.Scanner;
public class SmithNumber
{
public void SmithNumber()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the number to be checked");
int num=in.nextInt();
int num1=num;
int primesum=0;
int digitsum=0;
while(num1%2==0)
{
primesum=primesum+2;
num1=num1/2;
}
for(int i=3; i<=num/2; i+=2)
{
while(num1%i == 0)
{
if(i >= 10)
{
int i1=i;
while(i1 != 0)
{
int x=i1%10;
primesum=primesum+x;
i1=i1/10;
}
num1=num1/i;
}
if(i>0 && i<10)
{
primesum=primesum+i;
num1=num1/i;
}
}
}
while(num != 0)
{
int digit=num%10;
digitsum=digitsum+digit;
num=num/10;
}
if(primesum==digitsum)
{
System.out.println("It is a smith Number");
}
else
System.out.println("It is not a smith Number");
}
}

4) import java.util.Scanner;
public class DateValidation
{
public void Datevalidation()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the date: ");
int dd=in.nextInt();
System.out.println("Enter the month: ");
int mm=in.nextInt();
System.out.println("Enter the year: ");
int yy=in.nextInt();
System.out.println(dd+"/"+mm+"/"+yy);
if(yy>=1900 && yy<=9999)
{
if(mm>=1 && mm<=12)
{
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 ||
mm==7 ||mm==8 ||mm==10 ||mm==12))
{
System.out.println("The entered date is valid");
}
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9
|| mm==11))
{
System.out.println("The entered date is valid");
}
else if((dd>=1 && dd<=28) && (mm==2))
{
System.out.println("The entered date is valid");
}
else if((mm==2 && dd==29) && (yy%400==0 ||(yy%4==0 &&
yy%100!=0)))
{
System.out.println("The entered date is valid");
}
else
{
System.out.println("The entered date is not valid");
}
}
else
{
System.out.println("The entered date is not valid");
}
}
else
{
System.out.println("The entered date is not valid");
}
}
}

5) import java.util.Scanner;
public class CountDays
{
public void CountDays()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the date: ");
int dd=in.nextInt();
System.out.println("Enter the month: ");
int mm=in.nextInt();
System.out.println("Enter the year: ");
int yy=in.nextInt();
System.out.println(dd+"/"+mm+"/"+yy);
int tot=0;
if((dd>=1 && dd<=31))
{
if(mm==1)
{
tot=dd;
}
if(mm ==3)
{
tot=31+dd;
}
if(mm ==4 )
{
tot=dd+(31+31);
}
if(mm ==5)
{
tot=dd+(31+31+30);
}
if(mm ==6)
{
tot=dd+(31+31+30+31);
}
if(mm ==7)
{
tot=dd+(31+31+30+31+30);
}
if(mm ==8)
{
tot=dd+(31+31+30+31+30+31);
}
if(mm ==9)
{
tot=dd+(31+31+30+31+30+31+31);
}
if(mm ==10)
{
tot=dd+(31+31+30+31+30+31+31+30);
}
if(mm ==11)
{
tot=dd+(31+31+30+31+30+31+31+30+31);
}
if(mm ==12)
{
tot=dd+(31+31+30+31+30+31+31+30+31+30);
}
if(mm==2 && dd<=27)
{
tot=31+dd;
System.out.println("Corresponding day of the year is "+tot);
}
else if((yy%400==0 ||(yy%4==0 && yy%100!=0)))
{
tot=tot+29;
System.out.println("Corresponding day of the year is "+tot);
}
else
{
tot=tot+28;
System.out.println("Corresponding day of the year is "+tot);
}
}
else
{
System.out.println("error");
}
}
}
6) import java.util.Scanner;
public class Automorphic
{
public void Automorphic()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number to be checked");
int num=in.nextInt();
int num1=num;
int sqr=num*num;
String StrNum = Integer.toString(num);
String square = Integer.toString(sqr);
if(square.endsWith(StrNum))
{
System.out.println(num+" is an Automorphic Number");
}
else
System.out.println(num+" is not an Automorphic Number");
}
}

7) import java.util.Scanner;
public class karprekar
{
public void karprekar()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the number to be checked");
int n=in.nextInt();
int sqr=(int) Math.pow(n,2);
System.out.println("Square: "+sqr);
int sqr1=sqr;
int count=0;
while(sqr1 !=0)
{
sqr1=sqr1/10;
count++;
}
for(int i=1;i<=count; i++)
{
int zero=(int) Math.pow(10,i);
if(n==zero)
{
System.out.println("It is not a Karprekar number");
break;
}
int sum=(sqr/zero)+(sqr%zero);
if(sum==n)
{
System.out.println("It is a Karprekar number");
break;
}
else
{
System.out.println("It is not a Karprekar number");
break;
}
}
}
}

8) import java.util.Scanner;
public class LcmHcf
{
public void LcmHcf()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the two numbers in decending order");
int x=in.nextInt();
int y=in.nextInt();
int a=x;
int b=y;
int temp=0;
while(b !=0)
{
temp=b;
b=a%b;
a=temp;
}
int hcf=a;
int lcm= x*y/hcf;
System.out.println("The hcf of the given numbers is: "+hcf);
System.out.println("The lcm of the given numbers is: "+lcm);
}
}

9) import java.util.Scanner;
public class shift
{
public void shift()
{
Scanner in=new Scanner (System.in);
System.out.println("Enter the coded text");
String code=in.nextLine();
int l=code.length();
code=code+" ";
code=code.toUpperCase();
String dec="";
if(l>100)
{
System.out.println("INVALID CODE ! ");
}
else
{
System.out.println("Enter the shift number");
int shift=in.nextInt();
if(shift<1 || shift>26)
{
System.out.println("!!! Invalid Shift Value !!!");
}
else
{
int a=0;
int b=0;
char ch1,ch2;
for(int i=0; i<l;i++)
{
ch1=code.charAt(i);
ch2=code.charAt(i+1);
a=ch1+(shift-1);
b=ch2+(shift-1);
if((char) a=='Q' && (char) b=='Q')
{
a=32;
i++;
}
if(a>90)
{
a=a-26;
}
if(ch1==' ')
{
continue;
}
if(ch1 !=0)
{
dec=dec+(char)a;
}
}
System.out.println("Decoded Text : "+dec);
}
}
}
}

11) import java.util.Scanner;


public class PrimePalindrome
{
public void PrimePalindrome()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the Range ");
int m=in.nextInt();
int n=in.nextInt();
int c=0;
int freq=0;
int r=0;
if(m<n)
{
if(m < 3000 && n < 3000)
{
freq = 0;
System.out.println("The prime palindrome integers are:");
for(int i=m;i<=n;i++)
{
int t = i;
c = 0;
for(int j =1; j<=t; j++)

{
if(t%j == 0)
c++;
}
if(c == 2)
{
r = 0;
while(t>0)
{
int a = t%10;
r = r*10 + a;
System.out.println(r);
t = t/10;
}
if(r == i)
{
System.out.print(i+" ");
freq++;
}
}
}
System.out.println("\nFrequency of prime palindrome
integers:"+freq);
}
else
{
System.out.println("OUT OF RANGE");
}
}
}
}

12) public class Bubblesort


{
public void Bubblesort(int a[])
{
int temp=0;
for(int i=a.length-1;i>=0;i--)
{
for(int j=0;j<i;j++)
{
if(a[j] > a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int k=0;k<a.length;k++)
{
System.out.println(a[k]);
}
}
}

13) public class selectionsort


{
public void main(int a[])
{
int small=0;
int position;
int temp=0;
for(int i=0;i<a.length;i++)
{
small=a[i];
position=i;
for(int j=i;j<a.length;j++)
{
if(small>a[j])
{
small=a[j];
position=j;
}
temp=a[i];
a[i]=a[position];
a[position]=temp;
}
}
for(int k=0;k<a.length;k++)
{
System.out.println(a[k]+" ");
}
}
}

14) public class binarysearch


{
public void binarysearch(int a[],int n)
{
int u=a.length-1;
int l=0;
int c=0;
if(l<=u)
{
for(int i=0;i<a.length;i++)
{
int m=(u+l)/2;
if(n==a[m])
{
l=u+2;
System.out.println("found");
break;
}
if(n<a[m])
{
u=m-1;
c++;
}
if(n>a[m])
{
l=m+1;
c++;
}
}
}
else
{
System.out.println("not found");
}
}
}

15) public class Rbin


{
int a[]={6,8,17,21,45,60};
int u=a.length-1;
int l=0;
int c=0;
public void Rbin(int n)
{
if(l<=u)
{
int m=(u+l)/2;
if(n==a[m])
{
l=u+1;
System.out.println("found");
Rbin(n);
c++;
}
if(n<a[m])
{
u=m-1;
Rbin(n);
}
if(n>a[m])
{
l=m+1;
Rbin(n);
}
}
}
}

Potrebbero piacerti anche