Computer Project Work 2
Computer Project Work 2
Computer Project Work 2
Q1. WAP to overload a function with the class name Area and calculate the area
of parallelogram, rhombus and a trapezium.
import java.util.Scanner;
class Area
int ar=b*h;
double ar=1/2.0*(d1+d2);
double ar=1/2.0*(a+b)*h;
}
}
OUTPUT :-
Q2. WAP to overload a function with the class name Perimeter and calculate
the perimeter of square, a rectangle and circle.
import java.util.Scanner;
class Perimeter
void perimeter(int s)
int pr=4*s;
int pr=2*(l+b);
}
void perimeter(double r)
double pr=2*(22/7.0)*r;
OUTPUT :-
ARRAY PROGRAMS
Q1. WAP to input 10 values in an array to count the number of odd and even
numbers present in the array.
import java.util.Scanner;
class array_1
void display()
int o=0,e=0;
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
for(int j=0;j<10;j++)
if(a[j]%2==0)
e=e+1;
else
{
o=o+1;
OUTPUT :-
Q2. WAP to input 10 values in an array and display the highest and the lowest
value from the array.
import java.util.Scanner;
class array_2
void display()
System.out.println("Enter 10 numbers");
int a[]=new int[10];
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
int max=a[0];
int min=a[0];
for(int i=0;i<10;i++)
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
OUTPUT :-
Q3. WAP to input 10 values in an array and count the number of values divisible
by 5.
import java.util.Scanner;
class array_3
void display()
int c=0;
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
for(int i=0;i<10;i++)
{
if(a[i]%5==0)
c=c+1;
OUTPUT :-
Q4. WAP to input 10 values in an array and calculate the sum of all even
numbers present in the array.
import java.util.Scanner;
class array_4
void calculate()
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
for(int i=0;i<10;i++)
if(a[i]%2==0)
s=s+a[i];
OUTPUT :-
Q5. WAP to input 10 value in an array and calculate the sum of all the last digit
of each element.
import java.util.Scanner;
class array_5
void calculate()
int s=0,l=0;
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
for(int i=0;i<10;i++)
l=a[i]%10;
s=s+l;
}
OUTPUT :-
import java.util.Scanner;
class array_6
void display()
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
for(int i=0;i<10;i++)
{
int l=a[i]%10;
OUTPUT :-
Q7. WAP to input 10 values in a single-dimensional array and display the sum of
each element.
import java.util.Scanner;
class array_7
void display()
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
int r=0,d=0;
for(int i=0;i<10;i++)
int n=a[i],copy=n;
while(n>0)
r=n%10;
d=r+d;
n=n/10;
r=0;
d=0;
}
OUTPUT :-
Q8. WAP to input 10 values in a single-dimensional array and count the number
of palindromic number present in that array.
import java.util.Scanner;
class array_8
int palindrome(int n)
int r=0,d=0;
while(n>0)
r=n%10;
d=(d*10)+r;
n=n/10;
return d;
}
void count()
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
a[i]=sc.nextInt();
int c=0;
for(int i=0;i<10;i++)
if(a[i]==palindrome(a[i]))
c++;
}
OUTPUT :-
SUM OF SERIES PROGRAM
Q. WAP to display the sum of the series with the class name SeriesSum.
S= + + + ………(
! ! ! )!
import java.util.Scanner;
class SeriesSum
int x,n;
double sum;
x=xx;
n=nn;
double find_fact(int m)
int i;
double f=1.0;
for(i=1;i<=m;i++)
f=f*i;
return f;
}
double find_power(int x,int y)
double power=Math.pow(x,y);
return power;
void calculate()
for(int i=2;i<=n;i=i+2)
sum=sum+(find_power(x,i)/find_fact(i-1));
void display()
void main()
System.out.println("Enter a number");
int num=sc.nextInt();
ob.calculate();
ob.display();
OUTPUT :-