Professional Documents
Culture Documents
import java.util.*;
class prog2
{double p,r,t,S_I;
Scanner sc=new Scanner(System.in);
void accept()
{System.out.println("Enter p");
p=sc.nextDouble();
System.out.println("Enter r");
r=sc.nextDouble();
System.out.println("Enter t");
t=sc.nextDouble();
S_I=(p*r*t/100);
System.out.println("S_I="+S_I);
}
}
******velocity *******
class prog3
{double u,t,a,v;
void cal(double u,double t,double a)
{v=(u*t+1/2*a*t*t);
System.out.println("v="+v);
}
}
******Area of a Rectangle******
import java.util.*;
class prog4
{double l,b,area;
Scanner sc=new Scanner(System.in);
void accept()
{System.out.println("Enter l");
l=sc.nextDouble();
System.out.println("Enter b");
b=sc.nextDouble();
area=(l*b);
System.out.println("area of a rectangle=" +area);
}
}
*******Eligibility to Vote*******
import java.util.*;
class prog5
{int age ;
Scanner sc=new Scanner(System.in);
void cal()
{System.out.println("enter age");
age=sc.nextInt();
if
(age>=18)
System.out.println("eligible to vote");
else
System.out.println("not eligible to vote");
}
}
********Check whether a no. is positive******
import java.util.*;
class prog7
{int a;
Scanner sc=new Scanner(System.in);
void accept()
{System.out.println("Enter a number");
a=sc.nextInt();
if(a==0)
System.out.println("number is zero");
else
if(a>0)
System.out.println("number is positive ");
else
System.out.println("number is Negative");
}
}
*********Check whether a no. is even or Odd****
import java.util.*;
class prog8
{int k;
Scanner sc=new Scanner(System.in);
void accept()
{
System.out.println("Enter a number");
k=sc.nextInt();
if
(k%2==0)
System.out.println("number is even");
else
System.out.println("number is odd");
}
public static void main (String args[])
{ prog8 obj=new prog8() ;
obj.accept();
}
}
********Find the Amount of Bill acc. to the Condition***
import java.util.*;
class Hotel
{
String name;
long mno;
double bill,gst,tamt,st;
Scanner sc=new Scanner(System.in);
void accept()
{
System.out.println("Enter the name of the customer");
name=sc.next();
System.out.println("Enter the mobile number");
mno=sc.nextLong();
System.out.println("Enter the amount of the bill");
bill=sc.nextDouble();
}
void calc()
{
gst=(.18*bill);
st=(.125*bill);
tamt=(bill+gst+st);
}
void dis()
{
System.out.println("Name of the customer:- "+name);
System.out.println("Mobile no. of the customer:- "+mno);
System.out.println("GST:- "+gst);
System.out.println("ST:- "+st);
System.out.println("Total Amount:- "+tamt);
}
public static void main(String args[])
{
Hotel obj= new Hotel();
obj.accept();
obj.calc();
obj.dis();
}
}
******Find the Total amount of The Bill***
import java.util.*;
class hotel2
{ String name;
long mno;
double bill,gst,st,tamt;
Scanner sc=new Scanner(System.in);
void accept()
{System.out.println("Enter the Name of the customer");
name=sc.nextLine();
System.out.println("Enter the Mobile No.of the customer");
mno=sc.nextLong();
System.out.println("Enter the Bill Amount of the customer");
bill=sc.nextLong();
}
void calc()
{gst=(.018*bill);
st=(.125*bill);
tamt=(bill+gst+st);
}
void display()
{ System.out.println("the Name of the customer:"+name);
System.out.println("the Mobile No.of the customer:"+mno);
System.out.println(" G.S.T:"+gst);
System.out.println("S.T:"+st);
System.out.println("Total Amount:"+tamt);
}
public static void main (String args[])
{ hotel2 obj=new hotel2();
obj.accept();
obj.calc();
obj.display();
}
}
*****Check whether a no. is prime or not****
import java.util.*;
class prog6
{
int n,i;
boolean flag=true;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("ENter the number");
n=sc.nextInt();
for(i=2;i<n;i++)
if(n%i==0)
{flag=false;
break;
}
if (flag)
System.out.println("number is not a Prime Number");
else
System.out.println("number is a Prime Number");
}
}
**** find how many roots a no. has****
import java.util.*;
class prog10
{double a,b,c,disc,root1,root2;
Scanner sc=new Scanner(System.in);
void input()
{System.out.println("Enter a");
a=sc.nextInt();
System.out.println("Enter b");
b=sc.nextInt();
System.out.println("Enter c");
c=sc.nextInt();
}
void calc()
{
disc=(b*b-4*a*c);
if (disc>0)
{
root1=-b+Math.sqrt(disc)/2*a;
root2=-b-Math.sqrt(disc)/2*a;
System.out.println("number has two real and unequal roots"+root1+" and
"+root2);
}
else
if(disc==0)
{
root1=-b/2*a;
root2=root1;
System.out.println("number has two real root"+root1+"and"+root2);
}
else
System.out.println("number has imaginary roots");
}
}
******Multiplication table*****
import java.util.*;
class prog19
{int i,a,p;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the value of a");
a=sc.nextInt();
for(i=1;i<=10;i++)
System.out.println(a+"X"+i+"="+(a*i));
}
}
******Factorial of a Number ****
import java.util.*;
class prog20
{int i,a,fact=1;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the value of a");
a=sc.nextInt();
for(i=1;i<=a;i++)
fact=(fact*i);
System.out.println("Factorial of a "+fact);
}
}
******Sum Of Even/Odd Number******
import java.util.*;
class prog21
{int i,n,sumEven=0,sumOdd=0;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
for(i=1;i<=n;i++)
if(i%2==0)
sumEven+=i;
else
sumOdd+=i;
System.out.println("Sum of even no."+sumEven);
System.out.println("Sum of odd no."+sumOdd);
}
}
***** Divisibility of a number by a Number****
import java.util.*;
class prog21
{int i,n,sumEven=0,sumOdd=0;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
for(i=1;i<=n;i++)
if(i%2==0)
sumEven+=i;
else
sumOdd+=i;
System.out.println("Sum of even no."+sumEven);
System.out.println("Sum of odd no."+sumOdd);
}
}
******Factors of A Number ******
import java.util.*;
class prog24
{
int i,a;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the number");
a=sc.nextInt();
for(i=1;i<=a;i++)
if(a%i==0)
System.out.println(" "+i);
}
}
if (flag)
System.out.println("Eligible to vote");
else
System.out.println(" Not Eligible to vote");
}
}
/*To Find the Eligibilty To vote Using Boolean
*
*/
import java.util.*;
class prog26
{int age;
boolean flag= true;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the age the person");
age=sc.nextInt();
if(age<18)
flag= false;
if (flag)
System.out.println("Eligible to vote");
else
System.out.println(" Not Eligible to vote");
}
}
/*
* TO Extract a digit
*/import java.util.*;
class prog27
{int n=1,d;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the number");
n=sc.nextInt();
while(n>0)
{ d=n%10;
System.out.println(""+d);
n=n/10;
}
/*
* To Find the Smallest and LArgest Digit of A number
*/
import java.util.*;
class prog29
{
int n=1,d,smallest=9,largest=0;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
while(n>0)
{ d=n%10;
if(smallest>d)
smallest=d;
if(largest<d)
largest=d;
n=n/10;
}
System.out.println("smallest"+smallest);
System.out.println("largest"+largest);
}
}
}
}
}
System.out.println("Sum of the digit"+sum);
}
}
/*
* TO Find the Reverse of a Number
*/
import java.util.*;
class prog30
{
int n,d,rev=0;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
while(n>0)
{ d=n%10;
rev=(rev*10)+d;
n=n/10;
}
System.out.println(rev);
}
}
/*
* To check Whether a number is a Palindrome or not
*/import java.util.*;
class prog31
{
int n,d,rev=0,original;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
original=n;
while(n>0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
if(rev==original)
System.out.println("Number is a palindrome");
else
System.out.println("Number is not a palindrome");
/*
* Tocheck whether a number is niven or not
*/import java.util.*;
class prog32
{
int n,sum=0,p=1,d,original;
Scanner sc=new Scanner(System.in);
void acc()
{
System.out.println("Enter the number");
n=sc.nextInt();
original=n;
while(n>0)
{
d= n%10;
sum=sum+d;
n=n/10;
d=original%10;
p=p+d;
n=n/10;
}
{ if(original==p+sum)
System.out.println("niven number");
else
System.out.println("not a niven number");
}
}
}
/*
* Sum Of Factorial
*/import java.util.*;
class prog35
{ double i,j,fact,n ,s=0;
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter n");
n=sc.nextInt();
for(i=1;i<=n;i++)
{ fact=1;
for(j=1;j<=i;j++)
fact=(fact*j);
s=(s+1/fact);
}
System.out.println(s+"");
}
}
/*
* Array to Display Numbers
*/import java.util.*;
class prog37
{ int i;
int a[]=new int[5];
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println("Enter five numbers");
for(i=0;i<5;i++)
a[i]=sc.nextInt();
for(i=0;i<5;i++)
System.out.print(a[i]+" ");
}
}
/*
* Entering an Array and Find even number
*/
import java.util.*;
class prog38
{ int n,i;
Scanner sc=new Scanner(System.in);
int a [ ]=new int[100];
void acc()
{ System.out.println("Enter the value of n");
n=sc.nextInt();
System.out.println("Enter elements");
for( i=0;i<n;i++)
a[i]=sc.nextInt();
for( i=0;i<n;i++)
if(a[i]%2==0)
System.out.println("Even number"+a[i]);
}
/*
* Sorting Of An Array
*/import java.util.*;
class array1
{int n,i,j,temp;
}
System.out.println("Sorted Array is:");
for(i=0;i<n;i++)
{ System.out.println(" "+a[i]);
}
}
}
/*
* To Find a number in an array
*/
import java.util.*;
class array2
{ int n,i,k,x;
boolean flag=false;
int a[]=new int [100];
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the value of n");
n=sc.nextInt();
System.out.println("Enter the Elements");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Enter the no. to be found");
x=sc.nextInt();
{ for (i=0;i<n;i++)
if(x==a[i])
{ flag=true;
k=i;
break;
}
if(flag)
System.out.println("Number found " + " position "+k);
else
System.out.println("Number not found");
}
}
}
/*
* to find Odd number in 1d Array
*/
import java.util.*;
class array3
{ int i,n,k;
int a[]=new int[100];
int b[]=new int[100];
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the value of n");
n=sc.nextInt();
System.out.println("Enter the Elements");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
{for(i=0;i<n;i++)
if(a[i]%2!=0)
b[k++]=a[i];
for(i=0;i<k;i++)
System.out.println(" "+b[i]);
}
}
}
/*
* To find Prime numbers in an array
*/import java.util.*;
class array4
{int i,n ,j;
int a[]=new int[100];
Scanner sc=new Scanner(System.in);
array4()
{ int i=0;
}
boolean isprime(int x)
{ boolean flag=true;
for(j=2;j<x;j++)
if(x%j==0)
{ flag=false;
break;
}
return flag;
}
void acc()
{ System.out.println("Enter the value of n");
n=sc.nextInt();
System.out.println("Enter the elements");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
for(i=0;i<n;i++)
if(isprime(a[i]))
System.out.println(" " +a[i]);
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(i+j==4-1)
System.out.print(" " +a[i][j]);
else
System.out.print(" ");
System.out.println();
}
int sum=0;
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
if(i+j==4-1)
sum=sum+a[i][j];
}
System.out.println(" Sum of Right Diagonal"+sum);
}
}
// To find maximum and minimum//
import java.util.*;
class array2d2
{
int i,j,m,n,min,max;
int a[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println("Enter the no. of rows");
m=sc.nextInt();
System.out.println("Enter the no. of columns");
n=sc.nextInt();
System.out.println("Enter the elements");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println(" originalmatrix");
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
min=a[0][0];
max=a[0][0];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{ if(max<a[i][j])
max=a[i][j];
if(min>a[i][j])
min=a[i][j];
}
System.out.println("minimum elements"+min);
System.out.println( " maximum element "+max);
}
}
// to find merge array//
import java.util.*;
class mergearray
{ int i,j,k,m,n;
int a[]=new int[10];
int b[]=new int[10];
int c[]=new int[20];
Scanner sc=new Scanner(System.in);
void acc()
{ int k=0;
System.out.println("Enter the value of m");
m=sc.nextInt();
System.out.println("Enter the elements");
for(i=0;i<m;i++)
a[i]=sc.nextInt();
System.out.println("ENter the value of n");
n=sc.nextInt();
System.out.println("Enter the elements");
for(j=0;j<n;j++)
b[j]=sc.nextInt();
{ for(i=0;i<m;i++)
c[k++]=a[i];
for(j=0;j<n;j++)
c[k++]=b[j];
for(i=0;i<k;i++)
System.out.print(" "+c[i]);
}
}
}
// to find sum of elements
import java.util.*;
class array2d1
{ int i,j,n,m,sum=0;
int a[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println("Enter the no. of rows");
n=sc.nextInt();
System.out.println("Enter the no. of columns");
m=sc.nextInt();
System.out.println("ENter the Elements");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
a[i][j]=sc.nextInt();
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
System.out.print(" "+a[i][j]);
System.out.println();
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
sum=sum+a[i][j];
System.out.println(" "+sum);
}
}
// to find corner elements //
import java.util.*;
class ar2d
{ int i,j,m,n;
int a[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the no. of rows");
m=sc.nextInt();
System.out.println("Enter the no. of columns");
n=sc.nextInt();
System.out.println("Enter the Elements");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
System.out.print(" "+a[i][j]);
System.out.println();
}
System.out.println("corner Elements");
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
if((i==0||i<=m-1)&&(j==0||j<=n-1))
System.out.print(a[i][j]+" ");
else
System.out.print(" ");
System.out.println();
}
}
}
}
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
if(i==j)
sum=sum+a[i][j];
}
System.out.println(" Sum of Left Diagonal"+sum);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
if(i+j==4-1)
System.out.print(" " +a[i][j]);
else
System.out.print(" ");
System.out.println();
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
if(i+j==4-1)
sum=sum+a[i][j];
}
System.out.println(" Sum of Right Diagonal"+sum);
}
}
// to find boundary elements//
import java.util.*;
class array2d3
{ int i,j,m,n;
int a[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the no. of rows");
m=sc.nextInt();
System.out.println("Enter the no. of columns");
n=sc.nextInt();
System.out.println("Enter the Elements");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
System.out.print(" "+a[i][j]);
System.out.println();
}
System.out.println("Boundary Elements");
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
if((i==0||j==n-1) || (i==m-1||j==0))
System.out.print(a[i][j]+" ");
else
System.out.print(" ");
System.out.println();
}
}
}
// Recursive Prime
import java.util.*;
class RECURPRIME
{ int i,j,n,x,p;
if( n==i)
return 1;
if(n%i!=0)
return Prime(n,(i+1));
else
return 0;
}
void acc()
if(n%i==0)
return i+SumOfFactor(n,(i+1));
else
return SumOfFactor(n,i+1);
}
void acc()
{ System.out.println(" Enter the Number");
x=sc.nextInt();
y=SumOfFactor(x,1);
System.out.println(" "+y);
}
public static void main (String a[])
{recsumOffactor obj=new recsumOffactor();
obj.acc();
}
}
// Recursive Reverse
import java.util.*;
class recreverse
{ int n,x,d,reverse=0;
int Reverse(int n)
{
if(n==0)
return reverse;
else
{d=n%10;
reverse=reverse*10+d;
return Reverse(n/10);
}
}
void acc()
{ Scanner sc=new Scanner(System.in);
System.out.println(" Enter the Number");
n=sc.nextInt();
x=Reverse(n);
System.out.println(x);
}
public static void main(String p[])
{ recreverse obj=new recreverse();
obj.acc();
}
}
// Recursive Armstrong??
import java.util.*;
class recArmstrong
{ int n,s;
int Armstrong(int n)
{ if(n==0)
return 0;
else
return (int)Math.pow(n%10,3)+Armstrong(n/10);
}
void acc()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
s=Armstrong(n);
if(s==n)
System.out.println(" Armstrong");
else
System.out.println(" Not an Armstrong");
}
public static void main(String p[])
{ recArmstrong obj=new recArmstrong();
obj.acc();
}
}
//Recursive fact//
import java.util.*;
class recursivefact
{ int n,p,x ;
Scanner sc=new Scanner(System.in);
int factorial( int n)
{ if(n<2)
return 1;
return n*factorial(n-1);
}
void acc()
{ System.out.println(" Enter the number");
x=sc.nextInt();
System.out.println(" "+factorial(x));
}
public static void main(String args[])
{ recursivefact obj=new recursivefact();
obj.acc();
}
}
// String Extract//
import java.util.*;
class strextrtact
{ String st,str;
int i,l,k=0;
char ch;
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println(" Enter the sentence");
st=sc.nextLine();
st=st+" ";
l=st.length();
for(i=0;i<l;i++)
{ ch=st.charAt(i);
if(ch==' ')
{ str=st.substring(k,i);
System.out.println(str);
k=i+1;
}
}
}
}
/*
* to find whether a word is palindrome or not using Boolean
*/
import java.util.*;
class strrevbool
{ int i,l;
String st,rev="";
boolean x;
char ch;
Scanner sc=new Scanner(System.in);
boolean Palindrome(String st)
{
l=st.length();
for(i=l-1;i>=0;i--)
{ ch=st.charAt(i);
rev=(rev+ch);
}
if(st.equals(rev))
return true;
else
return false;
}
void acc()
{System.out.println(" Enter a Word");
st=sc.next();
x=Palindrome(st);
if(x)
System.out.println("Palindrome Word");
else
System.out.println(" Not a Palindrome Word");
}
}
class strfindname
{ int i,n;
boolean flag;
String st,x,str;
String a[]=new String[100];
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println(" Enter the limit of Words");
n=sc.nextInt();
System.out.println("Enter the Words ");
for(i=0;i<n;i++)
a[i]=sc.next();
System.out.println("Enter the word to be found");
x=sc.next();
for(i=0;i<n;i++)
{ if(a[i].equals(x))
{
flag=true;
break;
}
}
if(flag)
System.out.println(x);
else
System.out.println("Not Found");
}
}
if(li>lmax)
{ lmax=li;
stmax=str;
}
k=i+1;
}
}
System.out.println("Largest Word"+stmax+" "+lmax);
}
}
// To extract vowel
import java.util.*;
class stvowelext
{ int j,l,a=0,e=0,i=0,o=0,u=0;
String st;
char ch,A,E,I,O,U;
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println(" Enter the Sentences");
st=sc.nextLine();
st=st.toUpperCase();
st=st+" ";
l=st.length();
for(j=0;j<l;j++)
{
ch=st.charAt(j);
if(ch=='A')
a=a+1;
if(ch=='E')
e=e+1;
if(ch=='I')
i=i+1;
if(ch=='O')
o=o+1;
if(ch=='U')
u=u+1;
}
System.out.println("u:"+u);
System.out.println("O:"+o);
System.out.println("I:"+i);
System.out.println("E:"+e);
System.out.println("A:"+a);
}
}
/*
* to find whether a word is palindrome or not
*/
import java.util.*;
class strrev
{ int i,l;
String st,rev="";
char ch;
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println(" Enter a Word");
st=sc.next();
l=st.length();
for(i=l-1;i>=0;i--)
{ ch=st.charAt(i);
rev=(rev+ch);
}
if(st.equals(rev))
System.out.println("Palindrome Word");
else
System.out.println(" Not a Palindrome Word");
}
}
r(i=0;i<l;i++)
{ ch=str1.charAt(i);
if(ch==' ')
{ str=str1.substring(k,i);
li=str.length();
System.out.println(str+""+li);
k=i+1;
}
}
}
// Mirroe Array//
import java.util.*;
class arrmirror
{ int i,j,m,n,temp;
int a[][]=new int[10][10];
int b[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{ System.out.println(" Enter the no. of Rows");
m=sc.nextInt();
System.out.println(" Enter the no. of Columns");
n=sc.nextInt();
System.out.println("Enter the elements");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
System.out.print(" "+a[i][j]);
System.out.println();
}
System.out.println(" Mirror Matrix");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ temp=a[i][n-1-j];
a[i][n-1-j]=a[i][j];
b[i][j]=temp ;
System.out.print(" "+b[i][j]);
}
System.out.println();
}
}
// to find whether a no. is perfecxt or not//
import java.util.*;
class perfect
{ int j,num;
Scanner sc=new Scanner(System.in);
public perfect()
{ int i=0;
}
public perfect(int nn)
{ int i=nn;
int sumoffactors(int i)
{ int sum=0,j;
for(j=1;j<i;j++)
if(i%j==0)
sum=sum+j;
return sum;
}
void check()
{
{ if(num==sumoffactors(num))
System.out.println("Perfect number");
else
System.out.println("not Perfect number");
}
}
public static void main ( String args[])
{ int num;
perfect obj=new perfect();
System.out.println("Enter the number");
num=obj.sc.nextInt();
obj.sumoffactors(6);
obj.check();
}
}
// Range of adam//
import java.util.*;
class rangeadam
{ int n,i,r,d,c ;
int a[]=new int[10];
Scanner sc=new Scanner(System.in);
int Reverse (int n)
{ if(n==0)
return 0;
else
return (n%10)*10+Reverse(n/10);
}
void acc()
{ System.out.println(" Enter the no. terms");
n=sc.nextInt();
System.out.println("Enter the numbers");
for(i=0;i<n;i++)
{ {a[i]=sc.nextInt();
d=a[i]*a[i];
r=Reverse(a[i]);
c=r*r;
}
if(c==d)
System.out.println(" Adam"+a[i]);
}
}
}
}
// to find sum of digit//
import java.util.*;
class recsumofdig
{ int n,s;
int sumOfDig(int n)
{
if(n==0)
return 0;
else
return (n%10)+sumOfDig(n/10);
}
void acc()
{ Scanner sc=new Scanner(System.in);
System.out.println(" Enter the number");
n=sc.nextInt();
s=sumOfDig(n);
System.out.println(" "+s);
}
public static void main(String x[])
{ recsumofdig obj=new recsumofdig();
obj.acc();
}
}
{ int i,j,m,n;
int a[][]=new int[10][10];
Scanner sc=new Scanner(System.in);
void acc()
{System.out.println("Enter the no. of rows");
m=sc.nextInt();
System.out.println("Enter the no. of columns");
n=sc.nextInt();
System.out.println("Enter the Elements");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("Original Matrix");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
System.out.print(" "+a[i][j]);
System.out.println();
}
System.out.println("Non Boundary Elements");
for(i=0;i<m;i++)
{for(j=0;j<n;j++)