Computer Project - Devansh
Computer Project - Devansh
ASSESSMENT SHEET
Section :- B
Roll No :- 20
ACKNOWLEDGEMENT
The success and final outcome of this project required a lot of
guidance and assistance from many people and I am extremely
privileged to have got this all along the completion of my project. All
that I have done is only due to such supervision and assistance and I
would not forget to thank them.
At last I would also like to thank the examiner for taking pains to go
through this project and I would also welcome suggestions for
improvement. -Devansh Shukla
3
INDEX
S.no Category Name of Page
Program No.(s)
* Arrays
1 Write a program
to enter 10
numbers in an
array and print the
sum of all even
numbers.
2 Write a program
to enter 10
numbers in an
array and print the
sum of the
numbers at even
positions.
3 Write a program
to enter 10
numbers in an
array and reverse
the array
4
elements without
using another
array.
4 Write a program
to input 15
numbers in an
Array and find the
average of the
odd numbers in
the inputed array.
5 Write a program
to enter 10
numbers in an
array and search
the given number
using linear
search technique.
6 Write a program
to enter 10
numbers in an
array and search
the given number
using binary
search technique.
7 Write a program
to input 16
numbers in 4
rows and 4
columns of the
Array of size 5x5.
5
in the String.
11 Write a program
to input any String
and convert the
String into Piglatin
Form.
12 Write a program
to input any String
and print only the
Palindrome words
of the String.
13 Write a program
to input a string in
the provided
manner.
14 Write a program
by considering the
following
statement to
change 26 to 15,
January to
August, Republic
to Independence,
and finally print
the updated
String, “January
26 is celebrated
as the Republic
Day of India”.
7
* Primary
Programs
15 Write a program
to input any
number and print
whether it is a
prime number or
not.
16 Write a program
to print the
following Pattern
17 Write a program
to print the
following
Fibonacci Series
18 Write a program
to input any
number and
check whether it
is automorphic or
not
19 Write a program
to input any age
and check
whether the
person is a Senior
Citizen or not.
20 Write a program
to input any
8
number and
check whether it
is a triple digit
number or not.
COMPUTER PROGRAMS
Arrays
7 Programs including Single Dimension Array, Linear
Search, Binary Search and Double Dimension Array
class sum
{
public static void main()
{
int a[] = new int[10];
int i, s=0;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter 10 Numbers”);
for( i=0 ; i<=9 ; i++ )
{
a[i] = sc.nextInt();
}
for( i=0 ; i<=9 ; i++ )
{
if( a[i] % 2 == 0 )
s = s + a[i];
}
System.out.println( “Sum of all the even numbers is” + s );
}
}
10
avg = s/c;
System.out.print(“The average of odd numbers of the Array
is”+avg”);
}
}
}
if(f == 1)
System.out.println(“Number exists and the position is” + (i+1));
else
System.out.println(“Number does not exist”);
}
}
f=1;
break;
}
else
if( n>a[m])
l = m+1;
else
if( n<a[m] )
u = m-1;
}
if (f==1 )
System.out.println(“Number exists”);
else
System.out.println(“Number does not exist”);
}
}
21
}
for(i=0 ; i<=3 ; i++)
{
s1=0;
s2=0;
for(j=0 ; j<=3; j++)
{
s3 = s3+a[i][j];
s2 = s2+a[i][j];
s1 = s1+a[i][j];
}
a[i][j] = s2;
a[j][i] = s1;
}
for(i=0 ; i<=4 ; i++)
{
for(j=0 ; j<=4 ; j++)
System.out.print(“The resulting matrix is”+a[i][j]);
}
System.out.println();
}
}
24
String
7 Programs including String Manipulation
Ques 8) Write a program to accept any string and convert the string
into uppercase also count the number of double letter sequence.
class uppercase
{
public static void main(String x)
{
int I, l, c=0;
char ch1, ch2;
x = x.toUpperCase()
l = x.length();
for(i=0 ; i<=l-2 ; i++)
26
{
ch1 = x.charAt(i);
ch2 = x.charAt(i+1);
if(ch1==ch2)
c++;
}
System.out.println(“No. of double lettered sequence is”+c);
}
}
Ques 9) Write a program to enter a String and print the String with
UpperCase and LowerCase letters reversed.
Class String
{
public static void main(String x)
{
int I, l;
char ch;
String y = “”;
l = x.length();
for(i=0 ; i<=l-1 ; i++)
{
ch = x.charAt(i);
if(Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
else
ch = Character.toLowerCase(ch);
28
y = y+ch;
}
y = y.trim();
System.out.print(“New String is”+y);
}
}
Ques 10) Write a program to input a String and count the number of
vowels in it.
class vowels
{
public static void main(String x)
{
int i, l, c=0;
char ch;
String y = “AEIOUaeiou”;
l = x.length();
for(i=o ; i<=l-1 ; i++)
{
ch = x.charAt(i);
if(y.indexOf(ch)!=-1)
c++
}
System.out.println(“Number of Vowels are”+c);
30
}
}
Ques 11) Write a program to input a string and convert the String into
Piglatin Form. (i.e. after converting the String into UpperCase place
the first vowel of the original word as the start of the new word along
with the remaining alphabets. The alphabets present before the vowel
being shifted towars the end followed by “AY”.)
class abc
{
public static void main(String x)
{
int i, l, p, s1, s2, s3;
char ch;
String y = “AEIOUaeiou”;
l = x.length();
x = x.toUpperCase();
for(i=o ; i<=l-1 ; i++)
{
ch = x.charAt(i);
32
if(y.indexOf(ch)! = -1)
{
p = i;
break;
}
}
s1= x.substring(0;p);
s2 = x.substring(p);
s3 = s2 + s1 + “AY”;
System.out.print(“Piglatin form of the inputed String is” + s3);
}
}
33
Ques 12) Write a program to input a String and print only the
palindrome words of the String.
class palindrome
{
public static void main(String x)
{
int i, l;
char ch;
String y = “”, z = “”;
x = x+””;
l = x.length();
for(i=0 ; i<=l-1 ; i++)
{
ch = x.charAt(i);
if(ch!=’’)
{
y = y=ch;
z = ch+z;
}
else
{
y = y.trim();
z = z.trim();
35
if(y.equalsIgnoreCase(z))
System.out.println(“Palindrome words of the String are”+y);
y = “”;
z = “”;
}
}
}
Ques 13) Write a program to accept a name and print the name in the
following manner.
INPUT:- Rajeev Kumar Singh
OUTPUT:- RKS
class string
{
public static void main(String x)
{
int i, l;
char ch;
String x = “”; y = “”;
x = x+””;
l = x.length();
for(i=0 ; i<=l-1 ; i++)
{
ch = x.charAt(i);
if(ch!=’’)
y = y+ch;
else
{
z = z+y.charAt(1);
y = “”;
37
}
System.out.println(“New string is”+z);
}
}
else
if(y.equalsIgnoreCase(“Republic”));
y = “Independence”;
else
if(y.equals(“26”));
y = “15”;
z = z+y+””;
y = “”;
}
}
System.out.println(“The updated String is” + z);
}
}
40
Primary
Programs
6 Programs including if else, pattern, series, and
general programs
int I, c=0;
for(i=1; i<=n; i++)
{
if(n%i==0)
c++;
}
if(c==2)
System.out.print(“Number is prime”);
else
System.out.print(“Number is not prime”);
}
}
{
For(j=5; j>=1; j--)
{
System.out.print(j);
}
System.out.println();
}
}
c = a+b;
System.out.print(c);
a=b;
b=c;
}
}
}
Ques 18) Write a program to input any number and check whether the
number is automorphic or not. (Number should exist in the last of its
square).
Class atomorphic
{
Public static void main(int n)
{
Int r, sq=n*n, p, c=0, a;
While(n!=0)
{
R=n%10;
48
N=n/10;
C++;
}
P = (int)Math.pow(10,c);
A = sq%p;
If(a==x)
System.out.print(“Number is Automorphic”);
Else
System.out.print(“Number is not Automorphic”);
}
}
49
Ques 19) Write a program to enter any age and check whether it is of
a senior citizen or not.
class senior
{
public static void main(int age)
{
if(age>=60)
System.out.print(“Senior Citizen”);
else
System.out.print(“Not a Senior Citizen”);
}
}
Ques 20) Write a program to input any number and check it is a triple
digit number or not.
Class triple
{
Public static void main(int n)
{
If(n>=100 && n<=999)
System.out.print(“Number is triple digit”);
Else
System.out.print(“Number is not triple digit”);
}
}