0% found this document useful (0 votes)
44 views72 pages

Name: Jesica Rani Kullu Class: 11Th Arts' Roll No: 32

This document contains a student's name, class, and roll number. It also contains two paragraphs thanking the student's teacher and principal for their support and encouragement on a school project. The student also thanks their parents and friends for helping finalize the project within the given time frame. The student's name and class details are provided at the end.

Uploaded by

HASIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views72 pages

Name: Jesica Rani Kullu Class: 11Th Arts' Roll No: 32

This document contains a student's name, class, and roll number. It also contains two paragraphs thanking the student's teacher and principal for their support and encouragement on a school project. The student also thanks their parents and friends for helping finalize the project within the given time frame. The student's name and class details are provided at the end.

Uploaded by

HASIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 72

NAME: JESICA RANI KULLU

CLASS: 11TH ‘ARTS’


ROLL NO: 32
I would like to express my special thanks
of gratitude to my teacher Mr.Sengupta
who gave me the golden opportunity to do
this wonderful project on Computer, who
also helped me in completing my project. I
came to know about so many new things I
am really thankful to them .I would also
like to thank our principal, Sister Monica
Rozario for her constant encouragement
and moral support, without which I would
never been able to give my best.
Secondly I would like to thank my
parents and friends who helped me a lot in
finalizing this project within the limited
time frame.
Jesica Rani Kullu
XI’Arts’
This structure is used to change the in normal
flow of control of programme execution.
These are also known as decision making
statement, control statement or jumping
statement.
Types of control structures
1. if- it is unidirectional control statement
that works only in one direction when the
condition is true.
2. if else-it is bi-dimensional control
statement that works in both the direction
i.e., true as well as false.
3. if else if(nested if)-it is a multibranding
control statement used when they are
more than one condition .
Q1. Write a programme to input the three sides of a
triangle in Cm to check and display whether it is
scalene, iso scalene or equilateral triangle.
import java.util.*;
class Triangle
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
double A,B,C;
System.out.println(“Enter three sides”);
A=in.nextDouble();
B= in.nextDouble();
C= in.nextDouble();
if(A!=B&&B!=C&&C!=A)
System.out.println(“Scalene triangle”);
else if(A==B&&B==C)
System.out.println(“Equilateral triangle”);
else
System.out.println(“Isoscalene triangle”);
}
}
Q3. Write a program to input the distance travelled by a
passenger to calculate and display the fair using the
given table.
Distance Fare
Up to 3Km Rs.5/Km
4 to 8Km Rs.4/Km
9 to 13Km Rs.3/Km
Above 13Km Rs.2/Km

import java.util.*;
class Display
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
double D,F=0;
System.out.println(“Enter the distance”);
D=in.nextDouble();
if(D<=3)
F=D*5;
if(D>=4&&D<=8)
F=D*4;
if(D>=9&&D<=13)
F=D*3;
if(D>=13)
F=D*2;
System.out.println(“Fare=”+F);
}
}
Q2. Accept a number and check it is palindrome
number or not.
import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A,D,R=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=N;A>0;A=A/10)
{
D=A%10;
R=R*10+D;
}
if(R==N)
System.out.println(“Palindrome number”);
else
System.out.println(“Not a palindrome number”);
}
}

4. switch case-in switch case programmes


executes according to choice of the user
from the items in the menu. It is also
known as menu-driven.
Q1.Write a program to input a number to find and
display
1.its square root
2.cube root
3.cube using switch case

import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
double n,sr=0;cr=0;c;
int ch;
System.out.println(“Press 1 for square root”);
System.out.println(“Press 2 for cube root”);
System.out.println(“Press 3 for cube”);
System.out.println(“enter your choice”);
ch=in.nextDouble();
System.out.println(“enter the number”);
n=in.nextDouble();
switch(ch)
{
case 1:
sr=Math.sqrt(n);
System.out.println(“Square root=”+sr);
break;
case 2:
cr=Math.pow(n,1.0/3);
System.out.println(“cube root=”+cr);
break;
case 3:
c=n*n*n;
System.out.println(“cube=”+c);
break;
default: System.out.println(“invalid choice”);
}
}
}
Looping control
statement
Loop
A loop is a statement used to repeat or iterate a
number of finite numbers of times.

TYPES OF LOOP
1. Fixed iteration-The loop in which the
number of iteration or repetition is known
in advance is known as fixed iteration.
Example – for loop
2. Variable iteration – The loop in which
the number of repetition is not known in
advance is known as variable iteration.
Example- while, do-while
Structure of loop :-
for(initialisation;condition;updation)
{
Body of loop
}
Q1. Write a program to print the factor of a number.
import java.util.*;
class Factor
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=1;A>n;A=A++)
{
if (N%A==0)
System.out.println(A);
}
}
}
Q2. Write a program to print even natural number from
1 to 20.
import java.util.*;
class Even_natural
{
public static void main(String args[])
{
for(int i=1;i>20;i=i+2)
{
System.out.println(i);
}
}
}
Q3. Write a program to print the sum of factors of a
number.
import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A, S=0;
System.out.println(“Enter a number”);
N=in.nextInt();
for(A=1;A<=N;A=A++)
{
if (N%A==0)
S=S+A;
}
System.out.println(“Sum of factors=”+S);
}
}

Q4. Accept number and print the sum of digits of the


number.
import java.util.*;
class Sum
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N=0,D=0, S=0;
System.out.println(“Enter a number”);
N=in.nextInt();
for(A=N;A>0;A=A/10)
{
D=A%10;
S=S+D;
}
System.out.println(“Sum of Digits=”+S );
}
}

Q5. Write a program to count the number of factors of a


number
import java.util.*;
class Count
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A,S=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=1;A<=N;A=A++)
{
if (N%A==0)
S=S+1;
}
System.out.println(“Number of factor=”+S);
}
}
Q6. Write a program to accept a number and check it is
prime or not.
import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A,S=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=1;A<=N;A=A++)
{
if (N%A==0)
S=S+1;
}
if(S==2)
System.out.println(“Prime”);
else
System.out.println(“Not a prime number”);
}
}
Q7. Write a program to accept a number and check
whether it is perfect number or not.

import java.util.*;
class Perfect_number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A,F=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=1;A<N;A=A++)
{
if (N%A==0)
F=F+A;
}
if(F==N)
System.out.println(“Number is perfect”);
else
System.out.println(“Number not is perfect”);
}
}

Q8. Accept a number and print sum of its digits.

import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N=0,D=0,S=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=N;A>0;A=A/10)
{
D=A%10;
S=S+D;
}
System.out.println(“Sum of digits=”+s);
}
}

Q9. Accept a number and check it is Armstrong number


or not.
import java.util.*;
class Armsrong_Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int A,N,D=0,S=0;
System.out.println(“Enter any number”);
N=in.nextInt();
for(A=N;A>0;A=A/10)
{
D=A%10;
S=S+D*D*D;
}
if(S==D)
System.out.println(“Number is Armstrong ”);
else
System.out.println(“Number is not Armstrong ”);
}
}

Q10. Print from 50 to 1 in reverse order.

import java.util.*;
class Reverse
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a=50; int b;
for(b=a;b>0;b--)
{
System.out.println(“Reverse number is= ”+b);
}
}
}

11. Accept a number and print the reverse of the


number.

import java.util.*;
class Reverse
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
Int R=0;
While(N>0)
{
Int d=n%10;
n=n/10;
R=R*10+d;
}
System.out.println(R);
}
}

12. Accept number and check it is Automorphic .

import java.util.*;
class Number
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,A,sq,R,D=0;
System.out.println(“Enter a number”);
N=in.nextInt();
for(A=N;A>0;A=A/10)
{
D=D+1;
}
sq=N*N;
R=sq%(int)Math.pow(10,D);
if(R==N)
System.out.println(“Automorphic number”);
else
System.out.println(“Not an Automorphic number”);
}
}

Sum of series
1.2+4+6+8+..........to 20 terms
import java.util.*;
class series
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int A,B,S=0;
for(A=2,B=1;B<=20;A=A+2,B++)
{
S=S+A;
}
System.out.println(“Sum=”+s);
}
}

2.1/2+1/6+1/10+1/14+..........to n terms
import java.util.*;
class series
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
double A,B,S=0,n;
System.out.println(“enter the value of n”);
n=in.next
for(A=2,B=1;B<=n;A=A+4,B++)
{
S=S+1/A;
}
System.out.println(“Sum=”+s);
}
}

3. 1-2+3-4+5-6+..............to n terms
import java.util.*;
class series
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int A,B,C,N,S=0;
System.out.println(“enter the value of N”);
N=in.nextInt();
for(A=1,B=2;C=1;C<=N;A=A+2;B=B+2;C=C+2)
{
S=S+A-B;
}
System.out.println(“Sum=”+s);
}
}

Pattern program
10 10 10 10 10
20 20 20 20
30 30 30
40 40
50
import java.util.*;
class Pattern
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int A,B,C=5;
System.out.println(“enter the value of n”);
n=in.nextInt;
for(A=10;A<=50;A=A+10)
{
for(B=1;B<=C;B++)
{
System.out.println(A);
}
System.out.println(c);
C=C-1;
}
}
}

2. *
*#
*#*
*#*#
*#*#*
*#*#*#
import java.util.*;
class Pattern
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int A,B,C=1,N;
System.out.println(“enter the value of N”);
n=in.nextInt;
for(A=1;A<=6;A=A+1)
{
for(B=1;B<=C;B++)
{
if(B%2==0)
System.out.print (“#”);
else
System.out.print (“*”);
}
System.out.println();
C++;
}
}
}

Encapsulation
The process of combining the data members and the
member function into a single unit is called
Encapsulation.
The unit is called Class.
Inheritance
The process of creating new class by sharing common
characteristics and behaviour of an existing class and
adding some additional features is known as
Inheritance.
In computer programming, a string is traditionally a
sequence of character other as a literal constant or
as some kind of variable. The latter may allow its
element to be mutated and the length changed, or it
may be fixed. Astring is generally understood as a
data type and is often implemented as an array data
structure of elements, typically characters, using
some characters encoding. A string may also denote
more general arrays or other sequence data types
and structures.
Depending on programing language and precise
data type used, a variable declared to be a string
may either cause storage in memory to be statically
allocated for a pre-determined maximum length or
employ dynamic allocation to allow it to hold a
variable numbers of elements.When a string appears
literally in source code, it is knoe\wn as astring
literalor an annonymous string. In a formal
language, which are used in mathematical logic and
theoritical computer science, a string is a finite
sequence of symbols that are chosen from a set
called an alphabet.
Examples of string “School”, “xy.Tmp.3x 12.PT”

WHAT IS A CHARACTER?
Any individual alphabet, digit or a symbol
enclosed within single quotes is known as
character in java. Its data type is char and size
is 2 bytes.
Eg. ‘A’ , ‘2’, ‘*’.
CHARACTER FUNCTIONS
These functions are used to perform some
operation on a character
1.Character.isletter() –
It is used to check whether the given character
is letter of an english alphabet or not.
Its return type is boolean.
Syntax :-
boolean <var> = Character.isLetter
(Character) ;
Example
boolean P = Character.isLetter(‘A’); true
2.Character.isDigit() –It is used to check
whether the given character is a digit or not. Its
return type is boolean.
Syntax :-
boolean <var> =
Character.isDigit(Character);
Example
boolean P = Character.isDigit (‘A’); false
Char P = ‘2’;
Character.isDigit (P);true
3.Character.isLetterorDigit () –
Its returns true if given character is either letter
or digit. Its return type is boolean.
Syntax :-
boolean <var> =
Character.isLetterorDigit (Character) ;
Example
boolean P = Character.isLetterorDigit
(‘A’); true
Char P = ‘2’;
Character.isLetterorDigit (P);true
Character.isLetterorDigit (P);false
4.Character.isWhiteSpace () –
It checks whether the give character is a blank
space or not. Its return type is boolean.
Syntax :-
boolean <var> = Character.isWhiteSpace
(Character);
Example - boolean P =
Character.isWhiteSpace (‘ ’); true
boolean P = Character.isWhiteSpace (‘
A’); false
4.Character.isLowerCase () –
It checks whether the given character is
lower case or not. Its return type is
boolean.
Syntax :-
boolean <var> = Character.isLowerCase
(Character) ;
Example
boolean P = Character. isLowerCase (‘a
’); true
boolean P = Character. isLowerCase (‘
A’); false
5.Character.isUpperCase () –
It checks whether the given character is
UpperCase or not. Its return type is boolean.
Syntax :-
boolean <var> = Character. isUpperCase
(Character) ;
Example
boolean P = Character. isUpperCase (‘a
’); false
boolean P = Character. isUpperCase (‘
A’); true
6.Character.toLowerCase () –
It converts the given character into lower
case letter if it is an upper case letter
otherwise returns the same character. Its
return type is char.

Syntax :-
char <var> = Character.toLowerCase
(Character) ;
Example
char P = Character. toLowerCase (‘D’); d
char P = Character. toLowerCase (‘d’); d
char P = Character. toLowerCase (‘*’); *
7.Character.toUpperCase () –
It converts the given character into upper
case letter if it is an lower case letter
otherwise returns the same character. Its
return type is char.

Syntax :-
char <var> = Character. toUpperCase
(Character) ;
Example
char P = Character. toUpperCase (‘d’); D
char P = Character. toUpperCase (‘D’); D
char P = Character. toUpperCase (‘*’); *
1.A program to input a character to check and
display whether it is letter or not. If it is letter
diplaying after changing its case.
import java.util.*;
Class Display
{
public static void main ( String args[])
{
Scanner in = new scanner ( System.in );
Char k;
System.out.println (“ Enter any character”);
k = in.next().CharAt(O);
if (character.isLetter(k))
{
System.out.println (“It is a letter”);
if (character.isUpperCase (k))
{
K= character.toLowerCase(k);
System.out.println (k);
}
Case
{
K= character.toUpperCase (k);
System.out.print (k);
}
else
System.out.println (“Not a Letter”);
}
}
}
2.A program to input a character to check and
display whether it is letter, digit or symbol
import java.util.*;
Class Display
{
public static void main ( String args[])
{
Scanner in = new scanner ( System.in );
Char k;
System.out.println (“ Enter any character”);
k = in.next().CharAt(O);
if (character.isLetter(k))
{
System.out.println (“It is a letter”);
}
else if ( Character.isDigit (k))
{
System.out.println (“It is a Digit”);
}
else
System.out.println (“It is a Symbol”);
}
}
ASCII CODE
Every character in java have an integral value
or numeric value that is known as its ASCII
Code.
Full form of ASCII is American Standard Code
for Information or Instruction Interchange.
Character
ASCII Code
A-Z
65-90
a-z 97-122
0-9 48-57
Output of the following :
1.Char P = ‘2’;
Int q = (int) P;
System.out.println (“ P =” + P);
System.out.println (“q=” + q);
Output :
P=2
q = 50
2.Int P = 120;
Char q = (Char) P;
System.out.println (“ P =” + P);
System.out.println (“q=” + q);
System.out.print ( (q+1));
Output :
P = 120
q = x121
STRING FUNCTION
String N = “PM.123 abc”, M = “BANANA”, P =
“PAPAYA”
1.length () – It is used to find the count of
number in the string. Its return type is int.
Syntax
Int <Var> = String Variable.length ();
N.String (); 10
2.CharAt () –It is used to find the character at a
given index in a string. Its return type is char.

Syntax
Char <Var> = String Variable.CharAt
(index);
M.CharAt (3); A
3. indexOf (Character) – It returns the index
of the first occurance of the given character in a
string. Its return type is int.
Syntax
Int <Var> = String Variable.indexOf
(Character);
P.indexOf (A); 1
4. indexOf (Character,index) – It returns the
index of the given character from the given
index in a string. Its return type is int.
Syntax
Int <Var> = String Variable.indexOf
(Character,index);
P.indexOf (‘A’,2); 3
M.indexOf(‘N’,2); 2
5. lastIndexOf (Character) – It returns the
index of the last occurance of the given
character in a string. Its return type is int.
Syntax
Int <Var> = String Variable.lastIndexOf
(Character);
P.lastIndexOf (‘A’); 5
M.lastIndexOf (‘N’);4
6. subString (index) – It returns the part of a
string from the given index. Its return type is
string.
Syntax
String <Var> = String Variable. subString
(index);
N.subSString(4); 23 abc
“MP3”.sbuString(2);
7. subString (index1,index2) – It returns all
the characters of the string from index 1 to
index 2. Including the character at index 1 but
excluding the character at index 2. Is return
type is string.
Syntax
String <Var> = String Variable. subString
(index1,index2);
N.subSString(4,7); 23
P.substring(2,6); PAYA
8. replace() – It is used to replace a character
with another character or some string with
another sub string of the given string. Its return
type is string.
Syntax
String <Var> = String Variable.
(Char1,Char2);
M.replace(‘A’, ‘P’ ); BPNPNP
N.replace(“abc”, “xy”);
PM.123xy
9. trim () – It is used to remove all the blank
space from the begining and end of a string. Its
return type is string.
Syntax
String <Var> = String Variable.trim();
N.trim(); PM.123abc
10. equals () –It is used to check whether the
two strings are equal or not. Its return type is
boolean.
Syntax
boolean <Var> = String
Variable.equals(String Variable 2);
M.equals(P); false
“Rakesh”.equals
(“RakesH”); false

“RAKESH”.equals(“RAKESH”); true
11. equalsIgnoreCase() –It is used to check
whether the two strings are equal or not after
ignoring the case. Its return type is boolean.
Syntax
boolean <Var> = String
IgnoreCaseVariable.equals(String Variable
2);
M.equalsIgnore(P); false
“Rakesh”. equalsIgnore (“RakesH”); true
“RAKESH”. equalsIgnore (“RAKESH”);
false
12. startsWith() –It check whether the give
string being starting with given string or not.
Its data type is boolean.
Syntax
boolean <Var> = String Variable. startsWith
(subString);
N. startsWith (“PMI”); false
M. startsWith (“BA”); true
13.endsWith () –It check whether the give string
is ending with given string or not. Its data type
is boolean.
Syntax
boolean <Var> = String Variable. endsWith
(subString);
14. valueOf () –This function returns the object
holding the value of the specified string. All
types of data value can be
passed as argument to the valueOf () function.
It just returns the string value of it.
Syntax
String <Var> = String Variable.valueOf();
15. compareTo () –This function compares
two strings and returns an integer value. It
not only checks the quality of the strings but
also checks whether astring is bigger or
smaller that the other string. Its return type is
int.
Syntax
int <Var> = String Variable. compareTo ();
16. concat () – This function concatenates two
strings. It accepts a string as an argument and
concatenates it with the calling string. Its return
type is string.
Syntax
String <Var> = String Variable.concat ();
2.A program to input a name containing three
words and display the first name, middle name
and last name separately.
N = “RAM PRASAD SHARMA”

import java.util.*;
Class String
{
public static void main ( String args[])
{
Scanner in = new scanner ( System.in );
String N,FN,MN,LM;
int A,B;
System.out.println (“ Enter a name
containing three words”);
N = in.nextLine ();
A = N.indexOf (‘’);
B = N.lastindexOf (‘ ‘);
FN = N.subString (OA);
MN = N.subString (A+1,B);
LN = N. subString (B+1);
System.out.println (“ First name =” + FN );
System.out.println (“ Middle name=” + MN);
System.out.println (“ Last name =” + LN);
}
}
3.A program to input two any words and
check and display whether they are equal in
length or not. If they are not equal display the
longer word along with its length.
import java.util.*;
Class String
{
public static void main ( String args[])
{
Scanner in = new scanner ( System.in );
String M,N;
int L1, L2;
System.out.println (“ Enter two words”);
M = in.nextLine();
N = in.nextLine();
L1 = M.length ();
L2 = N.length ();
if ( L1 = = L2 )
System.out.println (“ Both are equal in length
“);
else if ( L1>L2);
{
System.out.println (“Longer word =” + M);
System.out.println (“Its Length =” + L1);
}
else
{
System.out.println (“Longer word =” + N);
System.out.println (“Its Length =” + L2);
}
}
}

DIGITAL NUMBER
SYSTEM
In digital number representation, various
number systems are used. The most common
number system used are decimal, binary, octal,
and hexadecimal system. Let us discuss these
number system briefly.
1. Decimal to binary
2. Binary to decimal
3. Decimal to octal
4. Octal to decimal
5. Octal to binary
6. Binary to octal
7. Decimal to hex decimal
8. Hex to decimal
9. Binary to hex
10.Hex to binary
Propositional Logic & Hardware
Any statement that may either evaluate
to true or false,
Ex – it is not raining.
The above statements evaluates to
either true or false, so it is
propositional logic.
 Compound preposition
It is a combination of two or more
simple preposition.
Ex – It is raining and wind is
blowing.
 Operator(connective)
An operator joins simple
proposition into compound
proposition. It is also called
connective.

DIFFERENT TYPES OF
CONNECTIVE
1. Disjunctive(OR) (+,v)
2. Conjunctive (AND) (‘.’,’
^’,’&’)
3. Conditional /implication
4. Bi-conditional
5. Negation (Not) (- , ‘, ~)

 Some related terms


Contingencies – The
preposition that have some
combinations of ones and zeros
in their output column (Truth
values) are called
contingencies.
Tautologies- The proposition
having nothing but ones in
their output column (Truth
table) are called Tautologies.
Contradiction – The
proposition having nothing but
only zeros in their truth table
column are called
contradiction.
Consistent statement – Two
statement are consist ant if and
only if their conjunction is not
a contradiction.
 Well formed Formula (WFF)
The other name for the proposition or
statement is called WFF.
Truth table-It is complete table of the possible
Truth values of a proposition.
Array is a collection of similar type of
elements that can be referred by a common
name.
Types of Array
1. Single Dimensional – array elements are
stored sequentially one after the other.
2.Double Dimensional – array elements are
stored in rows X column form.
1. Accept marks of 10 students in a subject
from the user and find the sum , average and
deviation from mean.
import java.util.*;
class Mean
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[10];
double avg=0,sum=;
System.out.println(“Enter 10 elements ”);
for(int i=0;i<10;i++)
{
a[i]=in.nextInt();
Sum +=a[i];
}
avg=sum/10;
System.out.println(“avg=”+avg);
for(int i=0;i<10;i++)
{
double dev=a[i]avg;
System.out.println(“roll number”+i+1+dev);
}
}
}
2. Accept 10 numbers from the user and
perform linear search.
import java.util.*;
class Search
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[10];
System.out.println(“Enter 10 elements ”);
for(int i=0;i<10;i++)
a[i]=in.nextInt();
int min=a[0];max=a[0];
for(int i=0;i<10;i++)
{
min=Math.min(a[i];min);
max=Math.max(a[i];max);
}
System.out.println(“min=”+min);
System.out.println(“max=”+max);
}
}
3. Program to arrange 1 numbers in
ascending order using bubble sort.
import java.util.*;
class Sort
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[10];
System.out.println(“Enter 10 elements ”);
for(int i=0;i<10;i++)
a[i]=in.nextInt();
System.out.println(“sorting begins”);
for(int i=0;i<10;i++)
{
for(int j=0;j<9;j++)
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
System.out.println(“Printing the sorted
array”);
for(int i=0;i<10;i++)
System.out.println(a[j]);
}
}
4. Program to arrange 1 number in
acensending order using selection sort .
import java.util.*;
class Sort
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[10];
System.out.println(“Enter 10 elements ”);
for(int i=0;i<10;i++)
a[i]=in.nextInt();
System.out.println(“sorting begins”);
for(int i=0;i<10;i++)
{
int min=i;
for(int j=i+1;j<10;j++)
{
if(a[i]<a[min])
{
int t=a[i];
a[i]=a[min];
a[min]=t;
}
}
}
System.out.println(“Printing the sorted
array”);
for(int i=0;i<10;i++)
System.out.println(a[i]);
}
}
5. Write a program to insert element at
specified position in a single dimensional
array .
import java.util.*;
class Insert_Array
{
public static void main(String args[])
{
int n,pos,w;
Scanner in=new Scanner(System.in);
System.println(“Enter number of elements you
want in array”);
n=s.nextInt();
int a[]=new int[];
System.out.println(“Enter all the elements ”);
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
}
System.out.println(“Enter the position where you want
to insert element”);

pos=s.nextInt();
System.out.println(“Enter the element you want
to insert”);
x=s.nextInt();
for(int i=(n-1);i>=(pos-1);i--)
{
a[i+1]=a[i];
}
a[pos-[]]=a[i];
System.out.println(“After inserting”);
for(int i=0;i<n;i++)
{
System.ot.print(a[i]+”,”);
}
}
}
6. Deletion
import java.util.*;
class Array
{
public static void main(String args[])
{
int n,x,flag=0;loc=0,i;
Scanner in=new Scanner(System.in);
System.println(“Enter number of elements you
want in array”);
n=s.nextInt();
int a[]=new int[];
System.out.println(“Enter all the elements ”);
for(int i=0;i<n;i++)
a[i]=s.nextInt();
System.out.println(“Enter the element you want
to delete “);
x=s.nextInt();
for(int i=(n-1);i>=(pos-1);i--)
{
if(a[i]==x)
{
flag=1;
loc=i’
break;
}
}
if(flag==1)
{
for(i=loc+1;i<n;i++)
a[i-1]=a[i];
System.out.println(“After Deleting”);
for(i=0;i<n-2;i++);
System.out.print(a[i]+”,”);
}
else
System.out.println(“Enter not found”);
}
}
7.MERGING
import java.util.*;
class Merging
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[5];
int b[]=new int[8];
int c[]=new int[a.length+b.length];
System.out.println(“Enter element in array
b”);
for(int=0;i<5;i++)
b[i]=in.nextInt();
int k=0;
System.out.println(“Merging begin.........”)
for(int j=0;j<8;j++)
{
if(j<5){
c(k++)=a[j];
c(k++)=b[j];
else
c(k++)=b[j];
}
System.out.println(“Printing the merged
array”);
for(int i=0;i<c.length;i++)
System.out.println(c[i]);
}
}
Types of function
1. Pure function-it does not change the value
of the received parameter/object.
2. Impure function-it modifies the value of the
received parameter/object.

Types of function definition


1. with parameter with return
2. with parameter without return
3. without parameter with return
4. without parameter without return
Different ways in which a function can be
called :
1. Call by value-when a function is called the
actual parameter is copied into formal
parameter, any change made in the formal
parameter does not reflect in actual parameter.
2.Call by reference-when a function is called a
reference is copied from actual to formal
parameter, any changes made in formal
parameter refers in actual parameter.
Q1. Write a program to input the perimeter of a
Triangle with parameter with return, with
parameter without return, without parameter with
return and without parameter without return.
Import java.util.*;
Class Perimeter
{
Int a,b,c,d;
Int Perimeter=0;
Int abcd(int a,int b, int c, int d);
{
Perimeter=a+b+c+d;
return(Perimeter);
}
Void abcd1( int a,int b, int c, intd)
{
Perimeter = a+b+c+d;
System.out.println(Perimeter);
}
Int abcd2()
{
Int a=10,b=11,c=12,d=13;
Perimeter=a+b+c+d;
return(Perimeter);
}
void abcd()
{
Int a=5,b=6,c=7,d=8;
Perimeter=a+b+c+d;
}
public static void main (String args[])
{
Perimeter obj1=new perimeter();
Int w=2,x=3,y=4,z=5;
Obj1.abcd(w,x,y,z);
Obj1.abcd1(w,x,y,z);
Obj1.abcd2();
Obj1.abcd2();
}
}
Recursion- it is the process in which a function
calls itself repeatedly from its own body until a
specified condition is satisfied.
Recursion has two parts:
1. Base case
2. Recursive case
THANK
YOU......................

You might also like