Akash Jha Computer Project Class X
Akash Jha Computer Project Class X
ON
COMPUTER APPLICATIONS
LABORATORY ASSIGNMENTS COMPLETED
DURING THE ACADEMIC YEAR 2020-2021
//To enter any number and check whether the number is automorphic or
neon .
import java.util.*;
class automorphic_neon
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
int sum=0,num, sq, t,d=0 ,ch,r;
System.out.print("Enter any number");
num=sc.nextInt();
System.out.println ("Enter 1 to find whether a number is automorphic
or not.");
System.out.println ("Enter 2 to find whether a number is neon or
not.");
ch=sc.nextInt();
switch (ch)
{
case 1://To find a number is automorphic or not
{
sq=num*num;
t=num;
while(t!=0)
{
d++;//no. of digits
t=t/10;
}
r=sq%(int)(Math.pow(10,d));
if(r==num)
{
System.out.print(num+ "is an AUTOMORPHIC number");
}
else
{
System.out.print(num+ "is not an AUTOMORPHIC number");
}
break;
}
case 2 ://to find a number is neon or not
{
sq = num *num;
while(sq != 0)
{
d = sq % 10;
sum += d;
sq /= 10;
}
if(num==sum)
{
System.out.println(num + " is a NEON Number.");
}
else
{
System.out.println(num + " is not a NEON Number.");
}
break;
}
default :System.out.println("WRONG INPUT");
break;
}
}
}
VARIABLE DESCRIPTION TABLE
// To enter any 2 nos. and print the HCF or LCMof the number.
import java.util.*;
class HCF_or_LCM
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
int a,b,ch,i;
System.out.println ("Enter any 2 nos.");
a=sc.nextInt();
b=sc.nextInt();
System.out.println ("Enter 1 to find the HCF of the 2 entered nos.");
System.out.println ("Enter 2 to find the LCM of the 2 entered nos.");
ch=sc.nextInt();
switch (ch)
{
case 1 : // To enter any 2 nos. and print the HCF of the nos.
for (i=a;i>=1;i--)
{
if (a%i==0 && b%i==0)
{
System.out.print ("HCF = "+i);
break;
}
}
break;
case 2 :// To enter any 2 nos. and LCM of the nos.
for (i=a;i<=a*b;i++)
{
if (i%a==0 && i%b==0)
{
System.out.print ("LCM = "+i);
break;
}
}
break;
default :System.out.print ("WRONG INPUT");
}
}// close of main method
}// close of class
VARIABLE DESCRIPTION TABLE
// To print the number of digits, sum of the digits and smallest digit
present in the number
import java.util.*;
class num_sum_small
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,c=0,ld,sum=0,small=9;
System.out.println("Enter any number");
n=sc.nextInt();
while(n!=0)
{
c++;
ld=n%10;
sum=sum+ld;
small = Math.min(ld, small);
n=n/10;
}
System.out.println("The number of digits = "+c);
System.out.println("The sum of the digits = "+sum);
System.out.println("The smallest digit is "+small);
} // close of main method
} // close of class
//To check whether the number entered by the user is present in array or
not.
import java.util.*;
class Linearsearch
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a []= new int [10] ;
int i,ns,f=0;
System.out.println("Enter a number to search");
ns=sc.nextInt();
System.out.println("Enter any 10 numbers");
for(i=0;i<9;i++)
{
a[i]=sc.nextInt();
if(ns==a[i])
{
f=1;
}
}
if(f==1)
System.out.print("The number is present.");
else
System.out.print("The number is not present.");
}
}
VARIABLE DESCRIPTION TABLE
//To check whether the number entered by the user is present in array or
not.
import java.util.*;
class search
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a []= {24, 28,34,56,78,89,90,99,100} ;
int i,ns,f=0,p=0;
System.out.println("Enter a number to search");
ns=sc.nextInt();
for(i=0;i<9;i++)
{
if(ns==a[i])
{
f=1;
p=i;
break;
}
}
if(f==1)
{
System.out.print("The number is present at position "+ (p+1));
}
else
{
System.out.print("The number is not present.");
}
}
}
VARIABLE DESCRIPTION TABLE
//To enter any 12 numbers and print them in ascending order using bubble
sort Technique.
import java.util.*;
class ascending12
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a[ ]=new int [12];
int i,j,temp;
System.out.println("Enter any 12 numbers");
for(i=0;i<12;i++)
{
a[i]=sc.nextInt();
}
//bubble sorting
for(i=0;i<11;i++)
{
for(j=0;j<11-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}//close of loop
}//close of outer loop
}
System.out.println("The number in ascending order are :");
for(i=0;i<12;i++)
{
System.out.println(a[i]);
}
}
}
//To enter any 12 numbers and print them in ascending order using
selection sort Technique.
import java.util.*;
class ascending_selectionsort
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a[]=new int [12];
int i,j,min,temp;
System.out.println("Enter any 12 numbers");
for(i=0;i<12;i++)
{
a[i]=sc.nextInt();
}
//Selection sorting
for(i=0;i<11;i++)
{
min=i;
for(j=i+1;j<12;j++)
{
if(a[min]>a[j])
{
min=j;
}
}//close of inner loop
//swap two numbers
temp=a[min];
a[min]=a[i];
a[i]=temp;
}//close of outer loop
System.out.println("The number in ascending order are");
for(i=0;i<12;i++)
{
System.out.println(a[i]);
}
}
}
VARIABLE DESCRIPTION TABLE
Variable Variable Variable description
name type