Ojas Computer Project Class X
Ojas Computer Project Class X
COMPUTER
PRACTICAL FILE
SUBMITTED TO: SUBMITTED BY:
Ms. Jaya Meghwani Ojas Saxena
Class: X – ‘B’
Roll No: 29
________________ ______________
External Examiner 1 Internal Examiner
ACKNOWLEDGEMENT
This I would like to thank my Computer Application
teacher Ms. Jaya Meghwani for her able guidance
and support in completing my project. I would also
like to extend my gratitude to the Principal Rev. Fr.
Gerald D’Souza for providing me with all the
facility that was required.
Date:
Class: X – ‘B’
2
INDEX
[Link]. Question Page Remarks
no.
WAP to input the names of 5 cities in an array 6
1
and search for names of the cities in an array
using linear search.
3
[Link]. Question Page Remarks
no.
5
PROGRAM-1
WAP to input the names of 5 cities in an array and search for names
of the cities in an array using linear search.
import [Link].*;
class city_search
{
public static void main(String args[])
{
String b[ ]=new String [5];
int g=0,j,y;
Scanner sc= new Scanner([Link]);
[Link]("Enter the name of any 5 cities");
for(j=0;j<5;j++)
{
b[j]=[Link]();
}
[Link]("Type the name of the city to be found");
String t=[Link]();
for(y=0;y<=4;y++)
{
if(b[y].equals(t))
{
g=1;
break;
}
}
if(g==1)
[Link]("Position of the city found is= "+(y+1));
else
[Link]("There is no such city");
}
}
6
Output:
7
PROGRAM-2
import [Link].*;
class binary
{
public static void main( )
{
int b[ ]=new int[5];
int g=0,j,t,m,v,mid;
Scanner sc= new Scanner([Link]);
[Link]("Enter the vlaues in ascending order");
for(j=0;j<5;j++)
{
b[j]=[Link]();
}
[Link]("Enter the elementto be search");
t=[Link]();
m=0;
v=4;
while(m<=v)
{
mid=(m+v)/2;
if(b[mid]==t)
{
g=1;
[Link]("Element found at position="+(mid+1));
break;
}
else if(b[mid]<t)
m
=mid+1;
else if(b[mid]>t)
8
v=mid-1;
}
if(m>v)
[Link]("No such Element name is found");
}
}
Output :
9
PROGRAM-3
class nested_loop
{
public static void main()
{
int i,j,a=1;
for(i=1;i<=5;i++ )
{
for(j=1;j<=i;j++)
{
[Link](a+" ");
a++;
}
[Link]( );
}
}
}
10
Output:
11
PROGRAM-4
class pattern2
{
public static void main()
{
int n=10,a;
char i,j;
for(i='A' ;i <='E';i++)
{
for(a=1;a<=n;a++)
{
[Link](" ");
}
n--;
for(j='A';j<=i;j++)
{
[Link](j);
}
[Link]( );
}
}
}
12
Output:
13
PROGRAM-5
WAP to input the age, gender (and Taxable Income of person male
or female) and Taxable Income of a [Link] the age more than 65
years or the gender is female, display “wrong category”. If the age is
less than or equal to 65 years and the gender is male<compute and
display the income Tax payable as per the table give below:
import [Link].*;
class taxonincome
{
public static void main()
{
Scanner sc= new Scanner([Link]);
double ictx=0,txin;
int age;
char gender;
[Link]("Enter the age ");
age=[Link]();
[Link]("Enter gender as male or female");
gender=[Link]().charAt(0);
[Link]("Enter the income of the person");
txin=[Link]();
if(age<=65 && gender=='m')
{
if(txin<=160000)
ictx=0;
else if(txin>160000 && txin<=500000)
14
ictx=(txin-160000)*0.1;
else if(txin>500000 && txin<=800000)
ictx=((txin-500000)*0.2)+34000;
else if(txin>800000)
ictx=((txin-800000)*0.3)+94000;
[Link]("Income Tax ="+ictx);
}
else
[Link]("Wrong criteria");
}
}
Output :
import [Link].*;
class asc_order
{
public static void main()
{ Scanner sc= new Scanner([Link]);
int x,y,z;
[Link]("Enter three Distinct values");
x=[Link]();
y=[Link]();
z=[Link]();
if(x>y && x>z)
{ if(y>z)
[Link](z+","+y+","+x);
else
[Link](x+","+z+","+x);
}
else if(y>x && y>z)
{
if(x>z)
[Link](z+","+x+","+y);
else
[Link](x+","+z+","+y);
}
else if(z>x && z>y)
{
if(x>y)
[Link](y+","+x+","+z);
else
[Link](x+","+y+","+z);
}
}
16
Output:
17
PROGRAM-7
import [Link].*;
public class duck_number
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int s,d=0,num;
[Link]("Enter your number to be checked.");
num=[Link]();
while(num!=0)
{
s=num%10;
num=num/10;
if(s==0)
d++;
}
if(d>0)
[Link]("The value given is a Duck Number.");
else
[Link]("The value given is not a Duck Number.");
}
}
Output:
19
PROGRAM-8
WAP to take a number from the user and check and print weather
the given number is Spy number or Not.
import [Link].*;
class spynumber
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int s,t=0,q=1,num;
[Link]("Enter the value");
num=[Link]();
while(num!=0)
{
s=num%10;
num=num/10;
t=t+s;
q=q*s;
}
if(t==q)
[Link]("Spy Number.");
else
[Link]("Not a Spy Number.");
}
}
20
Output:
21
PROGARM-9
WAP to input a number and print whether it is a HAPPY number or not.
import [Link].*;
class Happy_no
{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner([Link]);
[Link]("Enter a positive integer");
n=[Link]();
int d,s=0,x=n;
while(n>9)
{
while(n>0)
{
d=n%10;
s=s+(d*d);
n=n/10;
}
n=s;
s=0;
}
if(n==1)
{
[Link]("Number entered is a Happy Number.");
}
22
else
{
[Link]("Number entered is not a Happy Number.");
}}}
Output :
23
PROGRAM-10
Output :
24
Name Type Purpose
s string To store the string
inputted by the user.
s1 string To store the vowels of
both cases.
m int To find the length of
the string s.
c1 char To find whether the
string starts with a
vowel or not.
c2 char To find whether the
string ends with a
consonant or not.
Variable description table
25
PROGRAM-11
import [Link].*;
class abc
{
public static void main()
{
Scanner sc = new Scanner([Link]);
int j,m;
char ch;
String st1,st2="";
[Link]("Enter the string: ");
st1=[Link]();
m= [Link]();
for(j=0;j<=m-1;j++)
{
ch=[Link](j);
if([Link](ch)==-1)
st2=st2+ch;
}
[Link](st2);
}
}
26
Output:
27
PROGRAM-12
import [Link].*;
class num_series
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int j,e,u=0,g=1,y,o;
[Link]("Enter the values of X and N: ");
y=[Link]();
o=[Link]();
for(j=1;j<=o;j++)
{
g=g*j;
e=(int) [Link](y,j)/g;
u=u+e;
}
[Link]("Sum of the series is: "+u);
}
}
28
Output:
29
PROGRAM-13
import [Link].*;
class abc
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int i,a=1,b=4,c=5,d,n;
[Link]("Enter the limit");
n=[Link]();
[Link](a+","+b+","+c);
for(i=1;i<=n-3;i++)
{
d=a+b+c;
[Link](","+d);
a=b;
b=c;
c=d;
}
}
}
30
Output :
31
PROGRAM-14
import [Link].*;
class funcDak
{
public int alter(int a)
{
int b=a*2-3;
return b;
}
public String alter(String s)
{
int len=[Link]();
String n="";
for(int x=0;x<len;x++)
{
char c=[Link](x);
n=c+n;
}
return n;
}
public char alter(char c)
{
char m=(char)(c+1);
32
return m;
}
public static void main()
{
funcDak ob= new funcDak();
int x=[Link](8);
[Link]("First function's result is = "+x);
String s=[Link]("banana");
[Link]("Second function's result is = "+s);
}
}
Output:
33
Variable Description table
34
PROGRAM-15
import [Link].*;
class whileloop12
{
public static void main()
{
int s,d,j,n,o;
Scanner sc= new Scanner([Link]);
[Link]("Enter the digit");
o=[Link]();
[Link]("Digit \t Frequency");
for(j=0;j<=9;j++)
{
n=o;d=0;
while(n!=0)
{
s=n%10;
n=n/10;
if(s==j)
d++;
}
if(d>0)
[Link](j+"\t"+d);
}
}
}
35
Output :
36
PROGRAM-16
38
Output :
39
PROGRAM-17
import [Link].*;
class Prime_palindrome
{
public boolean isprime (int y)
{
int j, d=0;
for(j=1;j<=y;j++)
{
if(y%j==0)
d++;
}
if(d==2)
return true;
else
return false;
}
public boolean ispalin(int x)
{
int t=0,s,n=x;
while(x!=0)
40
{
s=x%10;
x=x/10;
t=10*t+s;
}
if(t==n)
return true;
else
return false;
}
public void show(int m1, int m2 )
{
int i;
boolean h, l;
for(i=m1;i<=m2;i++)
{
h=isprime(i);
l=ispalin(i);
if(h==true && l==true)
[Link](i+",");
}
}
public static void main ()
{
Scanner sc= new Scanner([Link]);
Prime_palindrome ob =new Prime_palindrome( );
int c,d;
[Link]("Enter the lower limit: ");
c=[Link]();
[Link]("Enter the upper limit: ");
d=[Link]();
[Link](c,d);
}
}
41
Output:
42
Variable description table
43
PROGRAM-18
import [Link].*;
class function1
{
public int fact(int b)
{
int j,g=1;
for(j=1;j<=b;j++)
{
g=g*j;
}
return g;
}
public static void main( )
{
Scanner sc= new Scanner([Link]);
int w,x,y,o,n;
double t;
function1 ob= new function1();
[Link]("Enter the value of o and n: ");
o=[Link]();
n=[Link]();
w=[Link](o);
x=[Link](n);
y=[Link](o-n);
t=1.0*w/(x*y);
[Link]("The value is: "+t);
}
}
Output:
44
Variable description table
Name Type Purpose
o int To store the value
coming from main
block.
j int To use as a counter in
the for loop.
g int To calculate value and
return it in the main
block.
o int To input the value
from the user.
n int To input the value
from the user.
45
PROGRAM-19
46
Output:
47
PROGRAM-20
48
Output :
49
PROGRAM-21
WAP to input a matrix of size 4x4 and print the sum of boundary
elements.
import [Link].*;
class matrix1
{
public static void main()
{
int j,k,t=0;
int a[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("enter the matrix ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
a[j][k]=[Link]();
}
}
[Link]("The original matrix is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](a[j][k]+" ");
}
[Link]();
}
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
if(j==0 || j==3 || k==0 || k==3)
t=t+a[j][k];
}
50
}
[Link]("The sum of boundary elements="+t);
}
}
Output :
51
Variable description table
PROGRAM-22
52
WAP to input a matrix of size 4x4 and print the sum of diagonals
elements of the matrix.
import [Link].*;
class matrix2
{
public static void main()
{
int j,k,s1=0,s2=0;
int a[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("Enter the matrix ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
a[j][k]=[Link]();
}
}
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
if(j==k)
s1=s1+a[j][k];
else if(j+k==3)
s2=s2+a[j][k];
}
}
[Link]("\nthe matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](a[j][k]+" ");
53
}
[Link]();
}
[Link]("The sum of primary diagonal elements: "+s1);
[Link]("The sum of secondary diagonal elements: "+s2);
}
}
Output :
54
Variable description table
55
PROGRAM-23
WAP to input a matrix of size 4x4 and print the transpose of the
matrix.
import [Link].*;
class matrix3
{
public static void main()
{
int j,k;
int a[][]=new int[4][4];
int b[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("Enter the matrix: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
a[j][k]=[Link]();
}
}
[Link]("\nThe original matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](a[j][k]+" ");
}
[Link]();
}
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
b[k][j]=a[j][k];
}
56
}
[Link]("\nThe transopse matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](b[j][k]+" ");
}
[Link]();
}
}
}
Output :
57
Variable description table
PROGRAM-24
58
WAP to input an integer array of size 10 and sort then in ascending
order by using selection sort.
import [Link].*;
class selectionsort
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int a[]= new int[10];
int j,q,min,k,u;
[Link]("Enter the array element: ");
for(j=0;j<=9;j++)
{
a[j]=[Link]();
}
[Link]("\nThe original array is: ");
for(j=0;j<=9;j++)
{
[Link](a[j]+",");
}
for(j=0;j<=9;j++)
{
q=j;
min=a[j];
for(k=j+1;k<=9;k++)
{
if(a[k]<min)
{
min=a[k];
q=k;
}
}
u=a[j];
a[j]=a[q];
a[q]=u;
59
}
[Link]("\nThe sorted array is: ");
for(j=0;j<=9;j++)
{
[Link](a[j]+",");
}
}
}
Output :
60
Variable description table
PROGRAM-25
61
WAP to input an int array of size 10 and sort then in descending order
by using bubble sort.
import [Link].*;
class bubblesort
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int a[]= new int[10];
int j,q,min,k,u;
[Link]("Enter the array element: ");
for(j=0;j<=9;j++)
{
a[j]=[Link]();
}
[Link]("\nThe original array is: ");
for(j=0;j<=9;j++)
{
[Link](a[j]+",");
}
for(j=0;j<=9;j++)
{
for(k=0;k<=8-j;k++)
{
if(a[k]<a[k+1])
{ u=a[k];
a[k]=a[k+1];
a[k+1]=u;
}
}
}
[Link]("\nThe sorted array is: ");
for(j=0;j<=9;j++)
62
{
[Link](a[j]+",");
}
}
}
Output :
63