[go: up one dir, main page]

Blue-J: ICSE Class - 10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 186

JMD-HGGM

Blue-J

FEATURES:
✓ Well Planned Notes
✓ Mini Test Papers
ICSE Class – 10th ✓ Smart Practice Notes
Computer Application (JAVA) ✓ Tricky Worksheets
✓ Group Classes with
Personal Attention
https://www.youtube.com/c/YPComputerClasses ✓ One to One Classes
https://www.instagram.com/yogesh.verma27/ ✓ YT Videos for Revision
✓ Sharing Student’s Progress
https://www.facebook.com/yogesh.verma.79219 with Parents
https://www.YPComputerClasses.in/

YOGESH VERMA (MCA) : 8329686472, 7798453624, 7798161873


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

2 Ch_no. Topics Page No.

1. Revision of class 9th Syllabus 4 – 84

2. Library Classes 87 – 90

3. Arrays 93 – 107

4. String Handling 110 – 129

5. User defined Methods 132 - 145

6. Class as the basis of all computation 148 - 158

7. Constructor 159 - 177

8. Encapsulation 179 - 184

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→2


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Ch_no. Topics Contents Page No.

1. Revision of class 9th Syllabus 4


3 1. POP & OOP 4
2. Principles of OOP & their benefits: 7
3. Introduction to Java 9
4. Values and data type 13
5. Data type info 15
6. Tokens 16
7. Basic structure of java Program 20
8. Escape Sequence Characters 26
9. Type Conversion 28
10. Operators in Java 29
11. Java expression 32
12. ++ / -- 35
13. Ternary operator 38
14. Input in Java 39
15. Input using Scanner 42
16. Input using InputIStreamReader 45
17. Mathematical Library Methods 49
18. Random() method 53
19. Conditional statement (IF) 55
20. Switch statement 62
21. Iterative Constructs 67
22. Nested loop 75
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→3
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit1: Introduction to OOP Concepts & Concept of Objects and Classes

Procedural Oriented Programming (POP) Object Oriented Programming (OOP)


4
1. Procedural programming paradigm focuses on 1. It is a very user friendly and a powerful approach to solve
breaking down a programming task into a basic to difficult problems. It bundles data and methods
collection of small modules known as sub routines together in a single unit which is known as data
or procedures / function. Encapsulation.
2. It follows top down approach in program design. It 2. It follows bottom up approach in program design.
uses procedures to operate on data. 3. It has access specifiers named Public, Private, Protected, etc.
3. It doesn’t have any access specifier. 4. Object Oriented Programming allows some special features
4. In POP, Overloading is not possible. such as Polymorphism, Inheritance and Data hiding.
5. It doesn’t provide Data Hiding so provides less 5. In OOP, Overloading is possible in the form of function
security. overloading and Operator overloading. It provides Data Hiding
6. Examples are ALGOL, COBOL, BASIC, PASCAL, so provides more security.
C etc. 6. The three most common examples are Java, C++ Python.

Limitation of POP Advantages of OOP


1. No restriction on data values 1. Data values are secured and Protected.
2. Cause Problems for the Programmers while debugging. 2. Error detection and correction become easier.
3. No reusability. 3. Complex Programs become easy.
Eg: BASIC, COBOL, C,…etc Eg: Java, C++, Python,…etc.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→4


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit1: Introduction to OOP Concepts & Concept of Objects and Classes

Features / Principles of OOP :


5 1. Class and Object. 2. Data Hiding. 3. Data Encapsulation 4. Abstraction. 5. Inheritance.
6. Polymorphism.
Class
Class is a user defined data type in which data members and member functions/methods are combined together in a
single unit. It is also known as Data Encapsulation. Class ➔ Data Members + Member Functions / Methods
Class helps to keep the data members in various visibility modes as private, public and protected. Usually, data members
of a class are kept in private or protected visibility modes and methods are kept in the public visibility mode. In java,
Default access specifier is public.

Private members are available to only own class and not accessible to function outside the class.
Private member data & function cannot be accessed outside the class. It is known as Data Hiding. They can be accessed
only through public members of the class.
Public members are the members which accessible from anywhere either inside or outside.
Or
A class is a blueprint or a prototype that defines characteristics & behaviour common to all objects of a certain kind. It is
the fundamental building block of Object Oriented Programming. How To Create A Class : Syntax:
Eg: class - Student public class class_name
characteristics: name, roll, std, marks. {
Behaviour: calc_tot(), calc_per(). private Data members declaration;
public Member functions declaration;
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→5
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit1: Introduction to OOP Concepts & Concept of Objects and Classes


Object :
6
Object is an instance (variable) of a class that is capable of holding actual data in memory locations. All objects of the same
class have same properties & functions. Objects can access only public members of the class.
Class and objects are related to each other in the same way as data type and variables.
Or
Object is an identifiable entity with some characteristics & behavior. It can be a place, a thing or a human.
Eg. Dog have state(name, colour, breed) & behaviour (barking, fetching, wagging the tail).

Syntax To Create A Object


Class_name Object_name1 = new Class_name();
Eg: Student s1 = new Student();

new: It is a keyword which is use to create an object and helps to allocate memory to an object.
Object can access the public member data & function of class using dot(.) operater.
How To Access : Example:
Syntax: S1.input();
ObjectName . publicMemberName; S1.x;
Data Encapsulation
Wrapping up of data members and member methods together in a single unit which is known as Data Encapsulation.
Abstraction:
Abstraction is the act of representing essential features without getting in to complexity of the system.
Eg: We know how to drive a car. But we don’t know the mechanism that makes the car move.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→6
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit1: Introduction to OOP Concepts & Concept of Objects and Classes


Principles of OOP & their benefits:
7
Encapsulation:
Wrapping and bundling of data & functions together in to a single unit called class is known as Encapsulation. It prevents
data from outside use & interference. Encapsulation is implemented through access-specifiers.
Benefits: Modularity & Information Hiding.

Inheritance: It is an ability of object of one class to acquire properties of object of another class. It follows the concept of
hierarchy.
Benefits: It helps in code re-usability. Allows less time in writing a program. Enables program execution faster.

Polymorphism: It means one thing many forms. It is an ability of one object to respond to same message in one or more
different ways.
Benefits: Function Overloading & Overriding.
Components of OOP
The major components of Object Oriented Programming are as follows:
1. Class 2. Object 3. Data Members & Methods 4. Access Specifier and Visibility Modes
Objects related to a class:
A class is a blueprint or prototype that defines variables & methods common to objects of same kind. It combines objects &
methods for manipulating the data in to one neat package.
Object factory:
A class is known as object factory as you can create numerous objects of similar characteristics & behaviour from a class. A
class determines the nature of an object.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→7
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit1: Introduction to OOP Concepts & Concept of Objects and Classes

Class encapsulate: A class encapsulates state & behaviour of an object i.e. data members & member methods.
8
Differentiate class & objects:
Class Objects
A class is a template for an object. A object is an instance of a class.

Class does not exist in the computer memory. Object exist in the computer memory.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→8


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit2: Introduction To Java

Types of Java
9

OOP, Interface, Package, Exception


CORE JAVA Handling, Threading, Applet, JDBC,
Beans etc.
JAVA
ADVANCE Servlet, Networking, RMI,
JAVA Swing, CORBA, JSP etc.
Hierarchy of Java

Developers
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→9
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit2: Introduction To Java


Java is a high level programming language (HLL) introduced by Sun Microsystems.
10
a. It is written and designed by James Gosling in year 1991.
b. It is pure Object Oriented programming language (OOP) & platform independent .
c. It is case sensitive language and robust language.
d. Old name of Java was Oak.
Ordinary Compiler:
In Ordinary compiler, source code is converted into machine code which is different for all the platforms.
C/C++/VB Source code (HLL) → Compiler → Machine Code (LLL)
Java Compiler:
In Java compiler, source code is converted into byte code in one go, which is same across all the platforms i.e. it can
be executed on any platform without changing it, by Java virtual machine.
Java code → Compiler → Class File (Byte Code) → Run(through JVM) → Machine Code
abc.java abc.class
Java Interpreter:
Interpreter converts source code into byte code (object code) line by line which is same across all the platforms i.e. it
can be executed on any platform without changing it, by Java virtual machine.
JVM: JVM stands for Java Virtual Machine. It is java run time system. Its work is to convert byte code into proper machine
code. It is a virtual processor for interpreting and executing java byte-code across various platforms.
Main concept of java:
WORA (Write Once Run Anywhere) means java byte codes can be executed on any platform without changing it, by Java
virtual machine.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→10
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit2: Introduction To Java

Java Characteristics / Java Features


11 a. OOP (Object Oriented Programming):
It is a very user friendly and a powerful approach to solve basic to difficult problems. It bundles data and
methods together in a single unit which is known as data Encapsulation.
• It follows bottom up approach in program design.
• It has access specifiers named Public, Private, Protected, etc.
• Object Oriented Programming allows some special features such as Polymorphism, Inheritance, Data
hiding and Abstraction.
b. Platform Independent:
After compilation the Java source code is converted in to Bytecode which is same across all platforms i.e. it
can be executed on any operating system without changing the code. So Java is known as platform
independent language.
c. Compiled as well as Interpreted:
Java source codes are compiled to bytecodes and bytecodes are interpreted by the JVM to give an output.
d. Simple:
Java syntax is very easy to learn and understand. It removes the complex features of the previous
programming languages like multiple inheritance and pointer.
e. It is More Secure, Portable, Reliable and Robust(Error free).

Name two types of Java programs:


a) Java Applets / Internet Applet: It is a java program which can run in a java enabled web browser. It is specifically
designed to be embedded in an HTML document.
b) Java Applications / Standalone system: They are standalone programs that can directly run on the machine (JVM).
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→11
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit2: Introduction To Java

Java Byte Code → Java source code is converted in to an intermediate code after compilation. This code is known as Byte
12
code. It is stored in file with .class extension & is same across all platforms. It can be executed only by Java Virtual Machine.
(source code is the code which is written by the programmer).

API → API stands for Application Programming Interface. It is the java library with pre-written classes and methods for easy
programming.

JDK → Java Development Kit (JDK) is an environment for building java application and applets. It includes tools for
developing & testing programs written in java.
JDK 1.1 → JDK 1.2 → JDK 1.3 → JDK 1.4 → JDK 1.5 → JDK 1.6 → JDK 1.7
Blue J → Blue J is an Integrated Development Environment (IDE) for executing programs written in Java. It has a viewer,
editor & debugger.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→12


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types Data Types


Name the character set used by Java:
Data → Raw facts and figures. Eg. (‘a’, ‘5’, ‘#’ etc).
Character set used by java is Unicode. It is a 2 bytes
13 Program → Collection of instructions (data).
character set which represents all the characters present in
Software → Collection/set of programs.
possible human languages.

Delimiters are the special characters.


They are used as -, ; , : , ?, ., ( ), { }, [ ], etc.

Data Types

Primitive / Primary / Non-primitive / Secondary / User defined /


fundamental Data type Reference / Composite/Derived Data type

➢ Integer (byte → short → int → long) ➢ Function / Methods


Numeric Types
➢ Floating number (float → double) ➢ Class and Object
➢ String
➢ Characters (char) ➢ Array
Non-Numeric Types
➢ Boolean (true/false)
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→13
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Difference between Primitive & Composite data-type


14
Primitive Data-type Composite Data-type
The data types that are already provided by java are The data types which are created by the programmer using
primitive data types. primitive data type are composite data types.
The size is fixed. The size depends on the number of variables & their types.
When a variable of primitive type is declared only one When a variable of class type is declared memory allocated
memory location is allocated. may vary.
‘new’ keyword is not used. ‘new’ keyword is used to declare the variables.

Rules for Data Types Character Rules:


Integer/whole numbers & Float/Double/real numbers Rules: ➢ A character constant is a single alphabet,
➢ An integer/float constant must have at least one digit. a digit or a single special symbol.
➢ Integer must not have a decimal point but float must have decimal point. ➢ It must have only one character.
➢ Both can be either positive or negative. ➢ It encloses within single inverted quotes.
➢ Default sign is positive. ➢ Both the inverted quotes should point to
➢ No commas or blanks are allowed within an integer/float constant. the left (‘ ‘).
➢ Eg: Integers → 426, +782, -8000 ➢ Range is 0 to 65536 (\u0000 - \uffff).
➢ double / Float → 34.5, -456.0, +34.543 etc. ➢ Eg : 'A' , 'i' , '5' , '=' , ‘$‘ etc.
String→ String is a collection of characters. It encloses with double quotes.
Eg: “123”, “Ram”, etc
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→14
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

All information about Data Types (40Q in one table


15
Wrapper Classes Data Types Size (bit/byte) Range Default values

Boolean boolean 8 bits (1 byte) true - false false


Byte byte 8 bits (1 byte) -128 to +127 0
Character char 16 bits (2 bytes) 0 to 65536 ‘\u0000’
Short short 16 bits (2 bytes) -32768 to +32767 0
Integer int 32 bits (4 bytes) -231 to 231 - 1 0
Long long 64 bits (8 bytes) -263 to 263 - 1 0l / 0L
Float float 32 bits (4 bytes) -3.4E+38 to 3.4E+38 0.0f / 0.0F
Double double 64 bits (8 bytes) -1.7E+308 to 1.7E+308 0.0d / 0.0D

Ascending order of Primitive Data Type:


✓ boolean < byte < char < short < int < long < float < double
Wrapper class:
It wraps or encapsulate primitive data type in a form of a class. They are used to convert primitive type to reference type
or vice versa. They are found in java.lang package which is default package in Java.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→15
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Token: Token is a smallest individual unit of a program. Tokens are building blocks of Java. Types of tokens are:
16 Types of tokens:
a) Keywords
b) Identifiers
c) Literals
d) Separators
e) Operators
f) Punctuators
(KILSOP)

Keyword
Keywords are reserved words provide by Java which convey special meaning to the compiler. They cannot be used as
identifiers. E.g. int, void, while, case, do, int, double, if, else, final, void, char, for, while, switch, case etc.

Literal (constants)
Literals are data items which do not change its value during the execution of the program.
Type of literals: Integer Literal → 20
Floating point / Real Literal → 2.5
Character Literal → ‘a’
String Literal → “Java”
Boolean Literal → false
Null Literal → null
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→16
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Token→ Literals
17
Differentiate String literal & Character literal.
String Literal Character Literal
It is a set of characters enclosed within double quotes. It is a single character enclosed within single quote.
It stored in a variable with String datatype. It stored in a variable with char datatype.
E.g. String s = “hello”; E.g. char ch = ‘a’;

Separators → Separators are the special characters in Java, which are used to separate the variables or characters.
Eg: ( ) (Brackets) – used to enclose any arithmetical or relational expressions.
{ } (Curly brackets) – used to enclose a group of statements which is called as compound/block statement
[ ] (Square brackets) – used to enclose subscript(index) or the cell number of a dimensional array.
, (Comma) – used to separate multiple variable under the same declaration.

Punctuators → Punctuators are the punctuation signs used as special characters in Java.
Eg: ? (question mark) – It is used in ternary operator.
; (semicolon) – It is a statement terminator. It indicates the end of a statement. Any line continued after semi colon
is treated as the next statement.
. (dot) - It is used to call the function with an object and used to access instance variables by using an object.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→17


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Variable
18 Variable is a name given to memory location to store data by user. On the other hand, It is the quantity which can change
during program execution. A variable must be declared before its use. It cannot be declared again in the same scope.

Identifier → Identifiers are the symbolic names given to various parts of program like variable, function, class & object etc.
Variable / Identifier Naming Rules
➢ A variable name is any combination of alphabets, digits, underscores(_) or dollar symbol ($) .
➢ The first character in the variable name must be an alphabet(a/A – z/Z), underscore ( _ ) or dollar( $ ). It can not be a
number. It is case sensitive & can be of any length.
➢ Blank spaces, commas, keywords (reserved words) or special symbol except an underscore or dollar are not allowed
within a variable name.
➢ E.g.: Correct variables → si_int , m_hra , pop_e_89 , $a , _b etc.
➢ Wrong variables → 1a, emp sal, no., if etc.
Variable Declaration
Syntax: Data type variable_name1, var2…….; final keyword / constant variable
Ex: int a; char ch; float per, sal; When a variable is declared using
Variable Initialization final keyword it becomes a constant
a. Static Initialization → Variable is initialized during the compile time. i.e. its value cannot be changed
Eg: int a = 10; during execution of the program.
char ch = ‘b’; double per = 66.5; E.g. final double pi = 3.14;
b. Dynamic Initialization → Variable is initialized during the runtime.
Eg: int a = 10, b=20; int c = a + b ; here c variable is initialized dynamically.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→18
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Differentiate ASCII & Unicode.


19
ASCII Unicode Character ASCII Code
It stands for American standard code for It stands for Universal code. A to Z 65 to 90
information interchange. Each character is The Unicode is a wide representation
assigned a specific numeric value, called the of characters in the numeric form. a to z 97 to 122
ASCII code. 0 to 9 48 to 57
It has 0 to 127 characters. It has 0 to 65536 characters.
Space 32

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→19


Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types


Basic Structure of Java Program public static void main():
20 Syntax: The program execution always starts from
class class_name main method & other sub functions are
{ executed from the main method. It is static so
public static void main(String args[ ]) // (String[ ] args) we don’t need to create an object to invoke it.
{
Program coding To Save a Program:
} Program file name should be same as class
} name. Extension of java file should be .java.

Example: File extension of source code &


class student intermediate code of Java:
{ Source code → .java
public static void main(String args[ ]) Intermediate code/Byte code → .class
{
System.out.println(“Hello Java”); String[] args : Java main method accepts a
System.out.println(“Welcome to YP computer Classes”); single argument of type String array. This is
} also called as java command line arguments.
}
o public → It represents that method will be accessible from anywhere.
o static → It is a special method which is invoked without object.
o void → It does not return any value.
o main() → It is the special function from where program execution starts.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→20
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Java Printing Statement


println() → It is used to print new line.
21 System.out.print() statement:
It is used to print message and variable value. Outputs
Eg: Working of println();
Syntax a) System.out.print( “hello” );
System.out.print(“msg”); System.out.println( “Java” );
System.out.print(varname);
b) System.out.println( “hello” );
System.out.print(“msg” + varname); System.out.print( “Java” );
Example
Outputs
int a = 10; c) System.out.print( “hello” );
1. System.out.print(“value of a = ” + a); System.out.print( “Java” );
2. System.out.print(a + “is the value of a”);
d) System.out.println( “hello” );
int a = 15, b = 50;
System.out.println( “Java” );
3. System.out.println( a + b );
4. System.out.println( “ Sum = ” + a + b );
5. System.out.println( “ Sum = ” + (a + b) );
6. System.out.println( a + b + “ is sum” );
7. System.out.println( a + “ ” + b);
8. System.out.println( “ ” + a + b);
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→21
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Java Basic Programs


Q3→ WAP to swap to numbers.
22
class Swap
Q1→ Find addition and product of given numbers. {
class FirstPro public static void main()
{ {
public static void main(String args[ ]) int A = 10, B = 20, C;
{ System.out.println(“Before Swapping”);
int a = 10, b = 20, sum, prod; System.out.println(“A = " + A);
sum = a + b; System.out.println(“B = " + B);
prod = a * b;
System.out.println("addition = " + sum);
System.out.println("product = " + prod);
System.out.println(sum + “ is an addition ");
} System.out.println(“After Swapping”);
} System.out.println(“A = " + A);
System.out.println(“B = " + B);
Q2→ Write the SOP line to print 10 + 20 = 30 in above Program }
}

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→22
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Programs using function arguments and without static keyword


23
Q4→ Find addition and product of given numbers. Q6→ WAP to swap to numbers.
class Swap
class FirstPro {
{ public void main(int A, int B)
public void main(int a, int b) {
{ int C;
int sum, prod; System.out.println(“Before Swapping”);
sum = a + b; System.out.println(“A = " + A);
prod = a * b; System.out.println(“B = " + B);
System.out.println("addition = " + sum);
System.out.println("product = " + prod);
System.out.println(sum + “ is an addition ");
}
} System.out.println(“After Swapping”);
System.out.println(“A = " + A);
Q5→ Write the SOP line to print 10 + 20 = 30 System.out.println(“B = " + B);
in above Program. }
}

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→23
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Programs using function arguments and with static keyword


24

Q7→ Find addition and product of given numbers. Q9→ WAP to swap to numbers.
class Swap
class FirstPro {
{ public static void main(int A, int B)
public static void main(int a, int b) {
{ int C;
int sum, prod; System.out.println(“Before Swapping”);
sum = a + b; System.out.println(“A = " + A);
prod = a * b; System.out.println(“B = " + B);
System.out.println("addition = " + sum);
System.out.println("product = " + prod);
System.out.println(sum + “ is an addition ");
}
} System.out.println(“After Swapping”);
System.out.println(“A = " + A);
Q8→ Write the SOP line to print 10 + 20 = 30 System.out.println(“B = " + B);
in above Program. }
}

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→24
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types ((Programs))

Q10→ WAP to input employee name and his salary of a month and print his annual salary.
25 class Employee
{
public static void main(String name, int salary, int asal)
{
int asal = salary*12;
System.out.println(“Employee Name = " + name);
System.out.println(“Annual Salary is = " + salary);
System.out.println(“Annual Salary is = " + asal);
}
}
Exercise→(Input using function arguments)
Q1→ Write a program (WAP) to input two numbers and calculate their sum, product, subtraction and division.
Q2→ WAP to input your name, gender and age and print these details.
Q3→ WAP to input rollno, name, marks of four subjects and calculate total & percentage.
Q4→ WAP to input distance in Meters and convert it into CM, KM, inch and feet.
(Hint cm = m*100, km = m/1000, inch = cm*2.5, feet = inch/12)
(1m=100cm, 1km=1000m, 1feet=12 inches, 1 inches=2.5cm)
Q5→ Temperature of a city in Fahrenheit degrees is input. Write a program to convert this temperature into Centigrade
degrees. T(°C) = (T(°F) - 32) × 5/9
Q6→ The length & breadth of a rectangle and radius of a circle are input. Write a program to calculate the area &
perimeter of the rectangle, and the area & circumference of the circle.
Q7→ If the total selling price of 15 items and the total profit earned on them is input, write a program to find the cost price
of one item.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→25
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Escape Sequence Characters


Escape Sequences Non-Graphical Character
26

Escape sequences are non-graphical characters that \n New line


control the way how data gets printed on output device. \t Horizontal tab
It always begins with a backward backslash ‘\’.
Eg: \n, \t, \” etc. \” To print double quote
Outputs
System.out.println(" Hello \n Java "); Hello \’ To print single quote
Java
\\ To print backslash
System.out.println(" Hello \t Java "); Hello Java
System.out.println(" Hello \” Java "); Hello “ Java \b Backspace
System.out.println(" Hello \\ Java "); \0 Null
\r Carriage return
\f Form feed

Whitespace: - It is tab, space, or newline. Java does


not enforce any indentation rules.

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→26
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit3: Values and Data Types

Type Conversion → Conversion of one datatype to another datatype is called type conversion.
27
There are two types of type conversions:
1. Implicit type conversion / type coercion 2. Explicit type conversion / narrowing conversion / type casting

Implicit type Conversion Explicit type Conversion


Conversion of one primitive datatype to another Conversion of one primitive type to another forcefully by the
automatically by the compiler is known as implicit conversion. programmer is Explicit conversion.
Destination type is larger than the source type. Source type is greater than the destination type.
The two types are compatible. The two types are not compatible.
Eg: int a = 2; Eg: double a = 2.5;
double x = a; int x = (int) a;
//a is converted to double type by compiler. //a is converted to int using typecast ‘()’ operator.

Hierarchy of data types indicates the increasing order of data types.


byte < char < short < int < long < float < double
If two data of different data types are operated upon then the result
automatically gets converted to their highest data type.
Eg1: int a = 10; double b = 20.5;
c = a + b; // here variable c must be declared as double type.
Eg2: What will be the data type of variable d in the image.
? JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→27
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit3: Values and Data Types

Type Conversion
28
Explicit Conversion of Literals
Examples
float f = 0.123F
double d = 23.34D
int a = 12;
long b = 12L

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→28


Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Operators:- Operators are special symbols which represents computation. They are applied on operand(s), which can be
29 values or variables.
Operand:- Operands are variables or constants on which operations are performed by the operator.

Operators can be classified in two ways:


1. Operation to be performed. 2. Number of operands.

➢ Arithmetic Operators → /, %, *, +, - ➢ Unary Operator (One Operand)


➢ Relational Operators → >, <, >=, <=, ==, != ➢ Binary Operator (Two Operands)
➢ Logical Operators → !, &&, || ➢ Ternary Operator (Three Operands)
➢ Assignment Operator → =
➢ Short hand/Compound assignment Op. → /=, %=, *=, +=, -=
➢ Conditional / ternary Operators → ?:
➢ Increment & Decrement Operators → ++, --

Unary Operator: The Operators which are associated with only one operand are unary operators. Eg: ++, --, +, -, !.
Binary Operator: The Operators which are associated with only two operands are unary operators.
Eg: /, %, *, + , -, <, >, etc. (Arithmetical and Relational Operators)
Ternary Operator: The Operators which are associated with only three operands are unary operators. Eg: ( ? : ) .
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→29
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Arithmetic Operators:
30 They are used for various mathematical calculations. They are /, % (Modulus / Remainder Op), *, +, -.
These operators are also called Binary Arithmetic Operator.

The result depends on the largest data type present in expression or left hand side variable.
a) System.out.println(11/2);
b) System.out.println(11.0/2); i) double a = 10 + 11/2;
c) System.out.println(11%2); System.out.println(a);
d) System.out.println(10%2); ii) double b = 10 + 11.0/2;
e) System.out.println(4%10); System.out.println(b);
f) System.out.println(4/10); iii) int c = (int)(10 + 11.0/2);
g) System.out.println(‘A’ + 10); System.out.println(c);
h) System.out.println(‘b’ + ‘B’); iv) int ch = ‘d’ + 10;
i) System.out.println(‘1’ + 10); System.out.println(ch);
j) System.out.println(“A” + ‘b’ + 10);
k) System.out.println(‘b’ + 10 + “A”);

Relational Operators:
They are used for comparisons between two operands(values). It returns boolean value. They are >, <, >=, <=, ==, !=.

Assignment Operator: Assignment operators are used to assigning value to a variable. The left side operand of the
assignment operator is a variable and right side operand of the assignment operator is a value. Eg. A=10 10 = A

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→30
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Logical Operators: They are used for combining various ! (NOT) Operator: The not operator works by
31 conditions together using an operator. It returns a boolean inverting (or negating) the value of its operand.
value comparing two or more boolean values. ! Condition1 Result
Logical operators are &&(And), ||(Or), !(Not). T F
F T
&& (AND) Operator : It returns true if both conditions are true.
It doesn’t check second condition if first condition is false. Logical Operators Symbol Format
Condition1 && Condition2 Result
T T T NOT ! !(a==b)
T F F
AND && (a>b)&&(a>c)
F T F
F F F OR || (a==b)||(a==c)

|| (OR) Operator : It returns true if either first condition or Precedence of logical operators is NOT (!), AND (&&) and OR (||).
second condition or both are true. It doesn’t check second If a statement contains all the three logical operators then NOT is
condition if first condition is true. operated first.
Condition1 || Condition2 Result
T T T
T F T
F T T
F F F

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→31
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Arithmetical Expression and Arithmetical Statement


32
The combination of operators & operands together is known as an Arithmetical expression / expression. When an
arithmetical expression is assigned to a variable then it is called an Arithmetical Statement.
Examples of Operator, Operand and Expression.
E.g. c = a + b; c = a + b;
This line is an Expression where a, b & c are operands and + and = are operators.
There are two types of expressions. Arithmetical Expression
Pure Expression / Pure Arithmetical Expression:
The expression with similar type of operands is known as pure expression. Eg: 5 + 10; int a=10; int b= a/3;
Impure Expression / Mixed Mode Expression / impure Arithmetical Expression :
The expression with different types of operands is known as Mixed Expressions. Eg: 5 + 6.2; int a=10; double b= a/3;
Precedence of operators and Name the operator with highest & lowest precedence.
The order in which the operands are operated by operators in an expression is known as precedence of operators.
Operators with same precedence are executed from left to right.
Operator with highest precedence is ( ), Operator with lowest precedence is =. In Maths:
Left to right
Q1→ Evaluate following expressions. In computer: 1. ()
Precedence of 2. /
2 – 10*3/2 + 100/11*2 and show steps. Operators→ 1. ( )
2. ++, -- 3. *
2 – 30/2 + 9*2 4. +
3. /, *, %
2 – 15 + 18 5. -
4. +, -
–13 + 18 Ans = 5 5. = 6. =
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→32
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Precedence of Operators:
33

Operators Precedence Associativity 8. Bitwise AND &

1. Bracket ( ), [ ] left to right 9. Bitwise exclusive OR ^

2. Increment, 10. Bitwise inclusive OR |


Decrement, ++ -- + - ! right to left
and unary
11. Logical AND &&
3. Multiplicative */% left to right
12. Logical OR ||
4. Additive + - left to right

5. Shift << >> >>> left to right 13. Ternary Operator ?:

6. Relational < > <= >= left to right = += -= *= /= %=


14. Assignment &= ^= |= <<= left to right
>>= >>>=
7. Equality == != left to right

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→33
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

How to solve Java Expressions


Q6→ Write the java expressions for the following.
34 Q2→ Evaluate following expressions.
2 – 10*3/2 - 100/9*2%3
2 – 30/2 - 11*2%3
2 – 15 - 22%3
–13 - 1
Ans = -14 Short hand/Compound assignment Operators:
Java provides some special Compound Assignment Operators,
also known as Shorthand Assignment Operators. It's called
Q3→ 2*3%4 –100/(10*3)/2 + 100%11*2
shorthand because it provides a short way to assign an
solve the expression.
expression to a variable. They are /=, %=, *=, +=, -=.
Q4→ 2 – 10*3%2 - 10/9*3%2
If int a = 5 then solve following expressions.
Q5→ 2*3%4 –100/10*(3/2) + 6*11%10 += a+=10 a = a+10 a = 15

Q6→ 5 + 3 > 7 && 7 >= 4 + 3 -= a-=10


/= a/=10
Q7→ 5 != 5 && 3 == 4
%= a%=10
A3) 3, Q4) 0 , Q5) -2 Q6) True Q7) False *= a*=10
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→34
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Operators ++ and --
35

Increment(++) / Decrement(--)

Pre-Operator Post-Operator
++a, --a a++, a--

Note:
➢ ++ increases value by 1 and - - decreases value by 1.
➢ Pre-Operator uses/transfers always updated value.
➢ Post-Operator uses/transfers always original value then update itself.

Differentiate Pre-increment & Post-increment operator.


Pre-increment operator: The value of operand is first incremented & then used.
E.g1. int a = 5; int x = ++a; value of x & a will be 6.
Post-increment operator: The value of operand is first used& then incremented.
E.g2. int a = 5; int x = a++; value of x will be 5 & a will be 6.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→35
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Practice Exercise of ++, -- Operators


36 Q4: int a = 10, x = 20, b;
Give the output of the followings: i) b = a++ + ++a + a++ + ++a;
Q1: int a = 10; System.out.println (b+“ ” + a); //__________
i) b = a++; ii) x -= --x + x-- + ++x + ++x +x--;
System.out.println(b+“ ”+a); //__________ System.out.println (“x = ” + x); //__________
ii) b = ++a;
System.out.println (b+“ ”+a); //__________ Q5: Give the output of the followings:
Q2: int a = 20; a) int x =20, y = 5, z;
i) b = --a; What is the value of z in
System.out.println(a+“ ”+b); //__________ z = ++x * (y – –) – y ; Show the steps.
ii) b = a--; b) int a = 10, b = 4, c, d;
System.out.println(a+“ ”+b); //__________ c = ++a – b-- * 2;
iii) b = b--; d = a-- / 2 * 5 - --b;
System.out.println( b ); //__________ System.out.print (c + “ ” + d+“ ”+a);
Q3: int x =20, y = 10, z; c) write the values of i, j, k, x.
What is the value of z in int i = 10;
z = ++x * (y – –) – y ; Show the steps. int j = 15 + i++;
Ans: z = ++x * (y – –) – y int k = ++j – i++%5;
9 A4) i) 48 14 ii) x = -77
int x = i++ + 2 * i; A5) a) 101 b) 3 23 10
21 * 10 - 9
z = 201
210 - 9
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→36
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Practice Exercise of ++, -- Operators


37 Q6→ Give the output of the followings: f) Evaluate x if a = 12, x=2
a) y += ++y + y-- + -- y; when int y=8 x *= a-- + a++ + --a + ++a + a--;
System.out.print (“value of x and a = ” + x + a);
b) int a = 7;
a += a++ + ++a + --a + a--;
int b = 10; g) What is the value of x1 if x=5.
b = b++; x1 = ++x – x++ + --x;
System.out.print(a + “ ”+ b);
h) Give the output of the followings:
c) If a = -3, b = -10, c=0,
int a =5;
find the output for X and Y.
a++;
X = ++a – b++ + c-- + ++b * (--c) *3/4
System.out.println(a);
Y = c-- + b++ + a - 2 - ++c +a
System.out.print(a++);
d) int x=5; a -= (a--) - (--a);
x= ++x + x++ +6; System.out.println(a);
System.out.print(“X=”+x); A6 a)33 b)39 10
int b = 3*x++ + ++x * 5; c) X=20, Y=-14
System.out.print(“B=”+b); i) int a = 4; d) X=18 B=154
e) m=5
int b = a-- + ++a%5 + a++;
e) What is the value of m after evaluating f) value of x and a = 116 11
System.out.print(“B=” + b); g) 6
the following expression: (int m=10, n=6) System.out.print((a++ * ++a)/5); h) 6
m - = 9%++n + (n++)/2; 65
i) B=12 7
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→37
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 4: Operators in Java

Ternary operator(?:)
38 Ternary operator or conditional operator requires 3 operands. It is an alternative to if-else statement. In ternary operator the
first operand must be a conditional expression. If the condition is true then operand 2(true expr) is executed otherwise
operand 3(false expr) is executed. It is also called the conditional assignment statement.
Syntax : var = condition ? true expr : false expr;

Q1: int a = 10, x = 20;


i) int b = (x < 30) ? 100 : 200 ;
System.out.println( b ); //__________
ii) int b = (!(x != 30)) ? x*10 : a+20 ;
System.out.println( b ); //__________
iii) char x = ‘A’; int a;
a = (x==‘a’) ? ‘a’ : ‘A’;
System.out.println( a ); //__________

Q2: boolean b; int a=20


i) b = (a+10 < 30) ? false : true ;
System.out.println( b ); //__________ Bitwise operator:
Bitwise operators act as special operators for the
ii) int c = (!(a >= 20) && (a < 20)) ? a*100 : a+20 ; manipulation of data at bit level. They can be applied
System.out.println( c ); //__________ only on data types like byte, short, long & char. E.g. &
(bitwise And), | (bitwise Or), ^ (XOR).
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→38
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java

Different ways to input in Java Q3→ WAP to find and display the simple interest
39 There are various ways to input the data values in Java. They areand amount by using function argument when
given below. principal, Interest and time are input from console.
1) By using a Function Argument class Swap
2) By using a Scanner Class {
3) By using a InputStreamReader Class public void main(int p, int r, int t)
4) By using Command Line Argument {
1) Programs using function arguments and without static keyword double si, amt;
si = (p*r*t)/100.0;
Q1→ Find Subtraction and Division of given numbers. amt = p+si;
class FirstPro System.out.println(“The Simple interest = “+si);
{ System.out.println(“The amount = “+amt);
public void main(int a, int b) }
{ }
int sub, div;
sub = a - b;
div = a / b;
System.out.println(“Subtraction = " + sub);
System.out.println(“Division = " + div);
System.out.println(sub + “ is a subtraction ");
}
}
Q2→ Write the SOP line to print 10 - 20 = -10 in above Program.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→39
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java

1) Programs using function arguments and with static keyword


Q6→ WAP to swap to numbers.
40
Q4→ Find addition and product of given numbers. class Swap
class FirstPro {
{ public static void main(int A, int B)
public static void main(int a, int b) {
{ int C;
int sum, prod; System.out.println(“Before Swapping”);
sum = a + b; System.out.println(“A = " + A);
prod = a * b; System.out.println(“B = " + B);
System.out.println("addition = " + sum);
System.out.println("product = " + prod);
System.out.println(sum + “ is an addition ");
}
} System.out.println(“After Swapping”);
System.out.println(“A = " + A);
System.out.println(“B = " + B);
Q5→ Write the SOP line to print 10 + 20 = 30 }
in above Program. }

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→40
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java 1) Programs using function arguments

Q7→ WAP to input the time in seconds. Display the time after converting them into hours, minutes and seconds.
41 Sample input: Time in seconds 5430
Sample output: 1 Hour 30 Minutes 20 Seconds
class Time
{
public static void main(int sec)
{
int min, hr;
min = sec/60;
sec = sec%60
hr = min/60;
min = min%60;
System.out.println(hr + “ Hour " +min +” Minutes “+sec+” Seconds”);
}
}
Exercise→(Input using function arguments) Programs
Q8→ Temperature of a city in Fahrenheit degrees is input. Write a program to convert this temperature into Centigrade
degrees. T(°C) = (T(°F) - 32) × 5/9
Q9→ The length & breadth of a rectangle and radius of a circle are input. Write a program to calculate the area &
perimeter of the rectangle, and the area & circumference of the circle.
Q10→ If the total selling price of 15 items and the total profit earned on them is input, write a program to find the cost price
of one item.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→41
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java

2) Input Data at run time using scanner Class


42 Scanner Methods To Input String, word and character.
Eg: import java.util.Scanner; // import java.util.*; next().charAt(0) → used to get character.
class Input_Data next() → used to get word.
{ nextLine() → used to get sentence/string.
public static void main(String args[ ])
{ Scanner Methods To Input All Type Numeric values
Scanner sc = new Scanner (System.in); nextByte() → Used to input byte type number.
nextShort() → Used to input short type number.
System.out.println("Enter Number "); nextInt() → Used to input Integer value.
int a = sc.nextInt(); nextLong() → Used to input long type number.
System.out.println("Enter fractional Number ");
double b = sc.nextDouble(); nextFloat() → Used to input float type number.
nextDouble() → Used to input double type number.
System.out.println("Enter a character ");
char ch = sc.next().charAt(0);

System.out.println("Enter a word ");


String wrd = sc.next();

System.out.println("Enter a String/Sentence ");


String str = sc.nextLine();

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→42
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java 2) Input Data at run time using scanner Class

Q1→ Find addition, subtraction, product and division of given Q2→ WAP to swap to numbers.
43 numbers. import java.util.Scanner;
import java.util.Scanner; class Swap
class FirstPro {
{ public static void main(String args[ ])
public static void main() {
{ Scanner sc = new Scanner (System.in);
Scanner sc = new Scanner (System.in); int a, b, c;
int a, b, sum, sub, prod,div; System.out.println("Enter two Numbers ");
System.out.println("Enter two Numbers "); a = sc.nextInt();
a = sc.nextInt(); b = sc.nextInt();
b = sc.nextInt(); System.out.println(“Before Swapping”);
sum = a + b; System.out.println(“a = " + a);
sub = a-b; System.out.println(“b = " + b);
prod = a * b;
div = a/b;
System.out.println("addition = " + sum);
System.out.println(“Subtraction = “ + sub); System.out.println(“After Swapping”);
System.out.println("product = " + prod); System.out.println(“a = " + a);
System.out.println(“Division = “ + div); System.out.println(“b = " + b);
} } }
} Q3→ Write the SOP line to print 10 * 20 = 200
if a=10 and b=20; c=a+b;
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→43
Ch1: Revision of class 9th
JMD HGGM
ICSE Class 10th Sub: Computer Applications

Unit 5: Input in Java 2) Input Data at run time using scanner Class

Q1→ WAP to input your name, gender and age and print these details.
44 Q3→ WAP to input two numbers in A and B and swap these two numbers with using extra variable and without using
extra variable.
Q4→ WAP to input rollno, name, marks of four subjects and calculate total & percentage.
Q5→ WAP to input distance in Meters and convert it into CM, KM, inch and feet.
(Hint cm = m*100, km = m/1000, inch = cm*2.5, feet = inch/12)
(1m=100cm, 1km=1000m, 1feet=12 inches, 1 inches=2.5cm)
Q6→ WAP to input employee name and Basic Salary (BS).
Calculate TA(travelling Allowance), DA(Dearness Allowance), HRA(House Rent Allowance), Total Salary(TS),
IT(income tax), PF(profit & funds) and Net Salary(NS).
TA = 35%of BS, DA = 30%of BS, HRA = 25% of BS, TS = BS + TA + DA + HRA;
IT = 5.6%of TS, PF = 7.5%of TS), NS = TS – ( IT + PF );
Q7→ Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this
temperature into Centigrade degrees. T(°C) = (T(°F) - 32) × 5/9
Q8→ The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to
calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
Q9→ If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of
this number.
Q10→ If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a
program to find the cost price of one item.

JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→44
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 5: Input in Java

3) Input Data at run time using InputStreamReader Class, use the following steps:
45
a) Import a package java.io because, because InputStreamReader class is available in it.
b) In main method, create objects of InputStreamReader and BufferedReader classes.
Eg: InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
Or
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

readLine()
It is a method which helps to get a string at run time using object of BufferedReader class. Its return type is String.
Syntax: String readLine();
Eg:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Enter String”);
String a = br.readLine(); parseXXX() is used to convert
System.out.print(“Enter all numeric values”); string into numeric datatype.
int b = Integer.parseInt(br.readLine()); a) Byte.parseByte()
double c = Double.parseDouble(br.readLine()); b) Short.parseShort()
byte d = Byte.parseByte(br.readLine()); c) Integer.parseInt()
short e = Short.parseShort(br.readLine()); d) Long.parseLong()
long f = Long.parseLong(br.readLine()); e) Float.parseFloat()
float g = Float.parse Float(br.readLine()); f) Double.parseDouble()
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→45
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 5: Input in Java

read() → It is used to get a character from keyboard but it returns ASCII Eg: System.out.print(“Enter a character”);
46
value of a inputted character at run time. Its return type is int. int a = br.read(); // B
Syntax: int read(); System.out.print(a); // 66
char ch = (char) br.read(); // B
Q7→ WAP to input employee name and his salary of a month
System.out.print(a); // B
and print his annual salary.
import java.io.*;
class Employee Character ASCII Code
{ A to Z 65 to 90
public static void main() throws IOException
{ A to z 97 to 122
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 0 to 9 48 to 57
System.out.println("Enter Employee name and his salary");
String name = br.readLine(); import java.util.Scanner;
int salary = Integer.parseInt(br.readLine()); class Employee
int asal = salary*12; { public static void main()
System.out.println(“Annual Salary is="+asal); { Scanner sc = new Scanner (System.in);
} System.out.println("Enter Employee name & his salary");
} String name = sc.nextLine();
int salary = sc.nextInt();
int asal = salary*12;
System.out.println(“Annual Salary is = " + asal);
} }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→46
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 5: Input in Java

4) Input data By using Command Line Argument


47

This is one of the ways to accept the data values from the user and pass the arguments (known as command line
arguments) to the main function like main(String args[ ]). The arguments tp the main function are passed through args[0],
args[1]. Args[2] and so on.

Q1→ Write a program in java to find the value of the given expression.
p = (a2 + b2 )/(a - b) Q2→ WAP in java to accept the
number of days using command line
public class Expression
argument and display the result after
{
converting it into number of years,
public static void main(String args [ ]) // (String [ ] args)
number of months and the remaining
{
numbers of days.
int a, b;
double p;
a = Integer.parseInt(arg[0]);
b = Integer.parseInt(arg[1]); Q3→ WAP in java to accept time in
p = (double)(a*a + b*b)/(a-b); seconds using command line argument
System.out.println(“The value of expression = " + p); and display the time after converting
System.out.println(“Division = " + div); them into hours, minutes and seconds.
} Eg: input Time in second = 5430
} Output: 1 Hour 30 Minutes 30 Seconds

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→47


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 5: Input in Java

Types of Errors in Java → There are three types of errors that occur in a computer program.
48 1. Syntax Error / Compile time Error
2. Logical Error
3. Runtime Error / Execution Error
1. Syntax Error / Compile time Error: These errors occur when the rules of the programming language are not followed.
They encountered during the compilation of a program.
Eg: missing semicolon, incorrect variable name, undefined terms etc.
2. Logical Error: The errors which occur due to wrong logic which gives incorrect results.
Eg: WAP to program to take three numbers. Divide the sum of first two numbers by the third number and display result.
int a=180,b =240, c=60,p;
p= a+b/c // wrong logic
p=(a+b)/c // correct logic
3. Runtime Error / Execution Error: The errors the occur during the execution of the program are runtime errors. They
may occur due to incorrect mathematical operations or by entering incorrect data values at the time of inputs.
Eg: dividing a number by zero, trying to find out the square root of a negative number.
Comments in Java→ Comments are remarks given by the programmer to explain aspect of the code to the program reader.
They are ignored by the compiler. They are also used for debugging purpose.
There are three (types) styles of writing comments:
✓ Single line comment: //………………………
✓ Multiple line comment: /*……………………*/
✓ Documentation comment: /**………………………………*/ used for a brief document or produce an HTML file that
documents your program.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→48
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods

Methods/Functions are subprograms or small block of code which perform specific action. Or
49 A large program can be divided into smaller subprograms. These subprograms are called as function.
Advantages of function:-
➢ Complexity of program is reduced.
➢ Debugging (error checking) can be done easily.
➢ Memory is saved. As only a single copy of the function is present in
the memory but it can be called many times in a program.
Categories Of Functions / Methods:
There are two Categories of functions.
1. Built-in methods/ Library methods / Pre-defined methods
Functions/Methods which are pre-defined in ‘JAVA’ language.
Or The methods which are created by the system developers
are said to be library methods or built-in methods.
Example → Math.pow(), Math.abs(), Math.sqrt(), etc.
2. User defined function → Methods are defined by the users itself.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→49


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods


The library methods (functions) are the in – built methods created by the developers. These predefined functions help the
50
user to perform certain tasks easily and quickly which are frequently used in Java Programming. Here we are going to learn
mathematical functions which are included in a class “Math” under “java.lang” package.

SYNTAX OF FUNCTION EXAMPLE


Return_type Function_name (Arguments)
1. int Math.min(int, int) int n = Math.min(4, 6); sop(n); // n = 4
2. double Math.min(double, double) double n = Math.min(4.7, 6.3); sop(n); // n = 4.7
3. int Math.max(int, int) int n = Math.max(6, 4); sop(n); // n = 6
4. double Math.max(double, double) double n = Math.max(4.7, 6.3); sop(n); // n = 6.3
double n = Math.pow(2.0, 3.0); sop(n); // n = 8.0
5. double Math.pow(double, double)
double n = Math.pow(5.0, -2.0); sop(n); // n = 0.04
double n = Math.sqrt( 4.0 ); sop(n); // n = 2.0
6. double Math.sqrt(double, double) double n = Math.sqrt( 6.25); sop(n); // n = 2.5
double n = Math.sqrt( -25.0); sop(n); // NaN
double n = Math.cbrt( 27.0 ); sop(n); // n = 3.0
7. double Math.cbrt(double, double) double n = Math.cbrt( 15.625 ); sop(n); // n = 2.5
double n = Math.cbrt( -3.375 ); sop(n); // -1.5
8. double Math.log( double ) double n = Math.log( 6.25 ); sop(n); // n = 1.8325
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→50
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods

SYNTAX OF FUNCTION EXAMPLE


51 Return_type Function_name (Arguments)
double n = Math.abs( 4.66 ); sop(n); // n = 4.66
9. double Math.abs( double )
double n = Math.abs( -6.25); sop(n); // n = 6.25
int n = Math.abs( 4 ); sop(n); // n = 4
10. int Math.abs( int )
int n = Math.abs( -6); sop(n); // n = 6
double n = Math.ceil( 8 ); sop(n); // n = 8.0
double n = Math.ceil( 8.49); sop(n); // n = 9.0
double n= Math.ceil( 8.5 ); sop(n); // n = 9.0
double n= Math.ceil( 8.99 ); sop(n); // n = 9.0
11. double Math.ceil( int/double )
double n= Math.ceil( -8); sop(n); // n = -8.0
double n= Math.ceil( -8.5); sop(n); // n = -8.0
double n= Math.ceil( -0.45); sop(n); // n = -0.0
double n= Math.ceil( -8.99 ); sop(n); // n = -8.0
double n = Math.floor( 8 ); sop(n); // n = 8.0
double n = Math.floor( 8.49); sop(n); // n = 8.0
double n = Math.floor( 8.5 ); sop(n); // n = 8.0
double n = Math.floor( 8.99 ); sop(n); // n = 8.0
12. double Math.floor( int/double )
double n = Math.floor( -8.0 ); sop(n); // n = -8.0
double n = Math.floor( -8.5); sop(n); // n = -9.0
double n = Math.floor( -0.45 ); sop(n); // n = -1.0
double n = Math.floor( -8.99 ); sop(n); // n = -9.0
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods

Math Methods → ceil() & floor()


52

Functions/Methods Answers
1. Math.ceil( 3.4 );
2. Math.ceil( 8 );
3. Math.ceil(4.2);
4. Math.ceil(-0.95);
5. Math.ceil(65.5);
6. Math.ceil(654);
7. Math.ceil(2.9);
8. Math.ceil(12.01);
1. Math.floor(-4.7);
2. Math.floor(16.3);
3. Math.floor(2.9);
4. Math.floor(-99.51);
5. Math.floor(-0.84);
6. Math.floor(64.6);
7. Math.floor(456);
8. Math.floor(-12.01);
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→52
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods

Math.random( )
53 This function returns a random number between 0 and 1. It returns a double data type value.
Syntax – double Math.random( );
1. To get an integer random number between 1 and n:
int rd = (int) (Math.random( )*n) + 1;
2. To get an integer random number between max and min:
int rd = (int) (Math.random( )*( max – min ) ) + min );
3. To get 0 and 1 as head and tail of a coin randomly.
int n = (int) (Math.random( ) * 2 );

Math.round()
This method returns the value of the argument rounded to the nearest int value.
0.5 and above is rounded to nearest higher int value & below 0.5 is rounded off to nearest lower int value.
Syntax - long Math.round(double a), or int Math.round(float a)

Math.rint()
This method is used to round the argument to nearest integer in floating point.
In case of 0.5 at decimal places it will round off to nearest even double value.
Syntax - double Math.rint(double a)

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→53


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 6: Mathematical Library Methods

Math Methods – round(), rint()


54

SYNTAX OF FUNCTION EXAMPLE


int n = Math.round( 8.0 ); sop(n); // n = 8
int n = Math.round( 8.49); sop(n); // n = 8
long n = Math.round( 8.5 ); sop(n); // n = 9
int n = Math.round( 8.99 ); sop(n); // n = 9
13. int / long Math.round(float/double)
int n = Math.round( -8.0 ); sop(n); // n = -8
long n = Math.round( -8.5); sop(n); // n = -8
int n = Math.round( -8.51 ); sop(n); // n = -9
int n = Math.round( -8.99 ); sop(n); // n = -9
double n = Math.rint( 8.0 ); sop(n); // n = 8.0
double n = Math.rint( 8.49); sop(n); // n = 8.0
double n = Math.rint( 8.5 ); sop(n); // n = 8.0
double n = Math.rint( 8.99 ); sop(n); // n = 9.0
14. double Math.rint( double )
double n = Math.rint( -8.0 ); sop(n); // n = -8.0
double n = Math.rint( -8.5); sop(n); // n = -8.0
double n = Math.rint( -8.51 ); sop(n); // n = -9.0
double n = Math.rint( -8.99 ); sop(n); // n = -9.0
System.out.println( Math.round(23.50) ); → 24 System.out.println( Math.rint(23.50) ); → 24.0
System.out.println( Math.round(24.50) ); → 25 System.out.println( Math.rint(24.50) ); → 24.0
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→54
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Decision Making statements


55 As soon as the command is given to execute a program, the control reaches the first statement of the program. It keeps
executing the statements sequentially unless end of the program is reached. Such movement of control is called as flow of
control. There are three ways of ‘flow of control’.
1. Normal flow of control 2. Conditional flow of control 3. Multiple branching of control
Normal flow of control:
It is the normal procedure where the control keeps on executing each and every statement of the program from top to bottom.

Conditional flow of control / Selection Statement


A selection or decision making statements allows selective execution of the statements based of given condition. It enables
subsequent selection of some of the several possible actions. So it is called conditional flow of control.

Conditional flow of control statements are divided into following ways:


1. if statement
2. If and only if statement
3. If - else statement
4. If – else - if ladder statement / multiple if If statement
5. Nested if

One way if Two way if Multiple if Nested if

If statement If - else statement If - else – if statement


Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→55
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

One way if statement - Syntax & Examples


56
If statement
It is used when a statement or a block of statements, to Q1- Find the output of e.g3 and e.g4 if
be executed based on a given condition, holds true. In a. per = 40
case, the condition is false, it ignores the block and b. per = 60
moves forward with the normal flow of control.
Eg3: Outputs
if(per>50)
Syntax:
{
if(condition)
System.out.print(“pass”);
{
System.out.print(per);
code
}
code
} Eg4:
Eg1: if(per>50)
if(per>50) System.out.print(“pass”);
{ System.out.print(per);
System.out.print(“pass”);
} Block or Compound statement:
Eg2: It is a set of two or more statements enclosed within a pair
if(per>50) of curly braces “{ }”.
System.out.print(“pass”);
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→56
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

if and only if statements, Two way if - Syntax & Examples


57

If and only if statements Two way if – else


It is a logical situation in which multiple statements can be It is a logical situation in which either of the two actions is
operated selectively. Here all conditions have been checked to be performed depending upon specified condition.
one by one. When the condition is true, it performs on set of
statements, otherwise, it performs another set of
Syntax: Eg: statements.
if(condition) if(n>0) Eg1:
{ Syntax:
{ if(per>50)
code if(condition) {
System.out.print(“Positive”);
code { System.out.print(“pass”);
}
} code }
if(n<0)
if(condition) code else
{
{ } {
System.out.print(“Negative”);
code else System.out.print(“fail”);
} }
code {
if(n==0) Eg1:
} code
{ if(per>50)
if(condition) code
System.out.print(“Zero”);
} System.out.print(“pass”);
{ } else
code System.out.print(“fail”);
code Note : Curly bracket is used for multiple statement. If we
} have single statement then no need bracket.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→57
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Multiple if - Syntax & Examples


58
Multiple if/ if-else if ladder
It has multiple conditions. It is executed from top to down. As soon as the condition in ‘if’ is true, the statements associated
with that ‘if’ are executed and rest of the if statements are bypassed. If non of the conditions are true statement in else are
executed. If the ‘else’ is not present, then no action is performed.
Eg1:
Syntax:
if(per>85)
if(condition) Eg2:
{
{ if(n>0)
System.out.print(“Grade A”);
code {
}
} System.out.print(“Positive”);
else if(per>70)
else if(condition) }
{
{ else if(n<0)
System.out.print(“Grade B”);
code {
}
} System.out.print(“Negative”);
else if(per>50)
else }
{
{ else if(n==0)
System.out.print(“Grade C”);
code {
}
} System.out.print(“Zero”);
else
{ }
System.out.print(“fail”);
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→58
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

If statement - Questions
59

Q1→ WAP to input a number and find out whether it is an odd number or even number.
Q2→ WAP to input a number and determine whether the year is a leap year or not.
Q3→ WAP to input a number and check the number is +ve number, –ve number or zero.
Q4→ WAP to input two numbers and find out the greatest number.
Q5→ WAP to input three numbers and find out the smallest number.
Q6→ WAP to input an alphabet and check whether it is vowel or not.
Q7→ WAP to input a character and check whether it is capital alphabet, small alphabet, number or symbol.
Q8→ WAP to input a three-digit number to obtain the reversed number and to determine whether the original and reversed
numbers are equal or not.
Q9→ Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through
the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
Q10→ WAP to input length and breadth of a rectangle and to find whether the area of the rectangle is greater than its
perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter.
Q11→ WAP to input to a number and check the number is buzz number or not.
( Buzz is the number which is divisible by 7 or ends with 7 ).

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→59


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java


Nested if - Syntax & Examples
60
‘if’ statement within if or else statement is called as nested ‘if’ statement.
Syntax: if(condition)
{
if(condition) Q12→ WAP to input name, gender(M/F) and age of a person and print output
{
according to following conditions.
code
}
else
{ Gender
code
}
} M/m F/f
else
{
if(condition)
{ age>21 age<=21 age>20 age<=20
code
}
else
He is major He is minor She is major She is minor
{
code
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→60
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

System.exit(0)
61 When System.exit(0) function is invoked(called), it terminates the execution of the program at that moment. Thus, the
execution of remaining statements of the program is ignored.
Syntax: System.exit(0);
Eg: Q13→ WAP to display the square and cube of a positive number. If entered number is not positive then program terminates
automatically by printing appropriate massage.
import java.util.Scanner;
class Pro_exit
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n;
System.out.println("Enter a Number: ");
n = sc.nextInt();
if(n<0)
{
System.out.println(“It is a negative number. So the program terminates”);
System.exit(0);
}
System.out.println(“Square of a number = ”+(n*n));
System.out.println(“Cube of a number = ”+(n*n*n));
} }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→61
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Multiple branching of control - SWITCH Statement


62 Switch statement is an alternative of multiple if statement. Switch is used to select sections of code depending on specific
integer or character values. It is multiple branch selection statement. The value of the variable is compared with the
constant value and the corresponding case is executed. If there is no matching case, default is executed.

Syntax: Note:
switch(variable / expression) ➢ Break statement is used to exit from case.
{ ➢ Default statement is executed when no case value is satisfied.
case value: ➢ Case values must be an integer or character. It can not be float and
statements string values.
break; // it is optional ➢ Cases can never have variable expressions.
case value: (for example case a +3: is wrong)
statements ➢ Multiple cases cannot use same expressions.
break; (case 2: case 1+1 is wrong)
case value: ➢ Multiple cases can use different expressions.
statements (case 2: case 1+2 is correct)
break; ➢ A switch with 10 cases would work faster than an equivalent if-else
---------- ladder
---------- ➢ A switch with two cases would work slower than an equivalent if-else.
default : // it is optional The limitations of switch are as follows:
statements o It doesn't allow ranges, Eg. case 90-100.
} o It requires either integers or characters and doesn't allow Strings & double.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→62


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Multiple branching of control - SWITCH Statement


63

Q1→ WAP to input a number and print week days name according to inputted number. 1 for Monday, 2 for Tuesday, … ...
7 for Sunday. If number is not between 1 to 7 then print invalid number.

A → Import java.util.*;
Class Weekdays case 3:
{ System.out.println(“Wednesday”);
public static void main(String args[]) break;
{ case 4:
int n; System.out.println(“Thursday”);
Scannner sc = new Scanner(System.in); break;
System.out.println(“Enter a number ”); case 5:
n = sc.nextInt(); System.out.println(“Friday”);
switch(n) break;
{ case 6:
case 1: System.out.println(“Saturday”);
System.out.println(“Monday”); break;
break; case 7:
case 2: System.out.println(“Sunday”);
System.out.println(“Tuesday”); break;
break; default:
System.out.println(“Invalid number”); } } }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→63
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Multiple branching of control - SWITCH Statement


64
Q2→ Find the output of following code snippet.
a) int a = 2; b) char x = ‘c’; int a = 10; c) int a = 3;
switch(a) switch(x) switch(a++)
{ { {
case 1: case ‘a’: case 1:
a++; a++; ++a;
break; break; break;
case 2: case ‘b’: case 2:
a+=2; a+=2; a+=2;
case 3: case ‘c’: case 3:
a++; a++; --a;
case 5: case ‘d’: case 5:
a*=3; a*=3; a*=3;
break; default: default:
default: a++; a++;
a++; } }
} System.out.println(“A = “ + a); System.out.println(“A = “ + a);
System.out.println(“value of a = “ + a);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→64


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Multiple branching of control - SWITCH Statement


65 Q3→ WAP to input an alphabet and check whether it is vowel or not using switch.
import java.util.*; import java.util.*;
class Weekdays class Weekdays
{ public static void main() {
{ Scannner sc = new Scanner(System.in); public static void main()
System.out.println(“Enter a number ”); {
char ch = sc.next().charAt(0); Scannner sc = new Scanner(System.in);
switch(ch) System.out.println(“Enter a number ”);
{ char ch = sc.next().charAt(0);
case ‘a’: switch(ch)
System.out.println(“vowel”); break; {
case ‘e’: case ‘a’:
System.out.println(“vowel”); break; case ‘e’:
case ‘i’: case ‘i’:
System.out.println(“vowel”); break; case ‘o’:
case ‘o’: case ‘u’:
System.out.println(“vowel”); break; System.out.println(“vowel”); break;
case ‘u’: default:
System.out.println(“vowel”); break; System.out.println(“not vowel”);
default: }
System.out.println(“not vowel”); } } } }}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→65
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 7: Conditional statement in Java

Switch - Questions
66
Q3→ WAP to input an alphabet and check whether it is vowel or not using switch.
Q4→ WAP to input a number and find out whether it is an odd number or even number using switch.
Q5→ WAP to input a month number and print month names like 1 for January, 2 for February……………..12 for December.
Q6→ WAP to input a month number and print season names like (12, 1, 2) for Winter, (3, 4, 5) for Spring, (6, 7, 8) for
Summer, (9, 10, 11) for Fall Season.
Q7→ WAP to print following menu.
1. Addition
2. Subtraction
3. Multiplication Q8→ WAP to input two numbers and one operator
4. Division and print result according to given operator.
5. Exit Eg: Enter two nos. 10 20 +
Enter your choice __ Result = 30
Enter two number ___ ____
Result is ___

Fall through:
If there is no break after a matching case construct, the statements of all the cases after a matching case are executed till
a break is encountered or the switch block is over. This is known as fall through.

Nested Switch Statement:


Switch statement within switch statement is called nested switch statement.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→66


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

These statements are used to perform a set of instructions repeatedly while the condition is true. iteration statements are
67 also called looping statements.
Types of Loop
1. Entry controlled loop (for, while loop)
➢ In this construct the test expression is evaluated first & then executes the statements (body of the loop.
➢ The loop is not executed if the condition is false for first time. Eg. for, while loop.
2. Exit controlled loop (do – while loop)
➢ In this construct the test expression is evaluated after the execution of the body of the loop
➢ The loop is executed if the condition is false for first time. Eg. do - while loop.

There are three Looping / Iteration statements.


1. for loop 2. while loop 3. do -- while loop

The loop has four different elements that have different purposes. These elements are:
i. initialization expression: Before entering in a loop, its variables must be initialized.
ii. Test Expression (Condition): The test expression decides whether the loop body will be executed or not. if
the test condition is true, the loop body gets executed Otherwise the loop is terminated. it means loop is
executed till the condition is true.
iii. The Body of the loop: The statements, which are executed repeatedly while the test expression evaluates to
true form the body of the loop.
iv. Modifier / increment / Decrement(++,- -) Expression: The increment/Decrement expression changes the
value of the loop variable.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→67
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

For loop
68
For loop is an entry controlled loop with all the expressions in one line. It is used for fixed number of iterations.
Syntax: for(initialization; Condition; ++/--) Block or compound statement
{ it is a set of two or more statements enclosed within a pair of curly
// loop body braces “{ }”.
} Eg. for(i=1;i<=4;i++)
{
Eg1: Print numbers from 1 to 10.
Block of statements;
for( int i = 1; i <= 10; i++)
}
{
System.out.print(i+ “ “); Eg4: Find outputs
} for( int i = 1; i <= 10; i+=2)
Eg2: Print numbers from 10 to 1. {
int i; System.out.print(i+ “ “);
for( i = 10; i >= 1; i- -) System.out.print(“Number”);
{ }
System.out.print(i+ “ “);
} Eg5: Find outputs
for( int i = 1; i <= 10; i+=2)
Note: System.out.print(i+ “ “);
System.out.print(“Number”);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→68


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

For loop - Questions


69 Q1→ WAP to print numbers from 1 to 10 and 10 to 1.
Q2→ WAP to print odd numbers up to N numbers.(1, 3, 5, 7………..N)
Q3→ WAP to print even numbers up to N numbers.(2, 4, 6, 8………..N)
Q4→ WAP to print squares of odd numbers up to N numbers.(12, 32, 52, 72………..N2)
Q5→ WAP to print cubes of even numbers up to N numbers.(2 3, 43, 63, 83………..N3)
Q6→ WAP to print even numbers from N to 2 numbers.(N……….6, 4, 2)
Q7→ WAP to print squares of odd numbers from N to 12numbers.(N2……72, 52, 32, 12)
Q8→ WAP to print the sum of following series
a) 1 + 2 + 3 + 4 ……….N
b) 13 + 33 + 53 + 73………..N3
c) 1/22 + 1/42 + 1/62 + 1/82………..1/N2
Q9→ WAP to print sum, product, average of first N natural number.
Q10→ WAP to input a number and print its factorial.
Q11→ WAP to input a number and its power and calculate the power.
Q12→ WAP to input a number and print its multiplication table.
Q13→ WAP to print Fibonacci series up to N terms. 0, 1, 1, 2, 3, 5, 8, 13, ………..N terms
Q14→ WAP to print Tribonacci series up to N terms. 0, 1, 2, 3, 6, 11, 20, 37, ………..N terms
Q15→ WAP to input a number and check whether it is prime number or not.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→69
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

There are different variations / types in the ‘for’ loop given below:
70 Infinite loop / Endless loop: We can specify more than one statements in a for loop
A loop that never terminates is known as infinite loop. for initialization and inc / dec. But they have to be comma
Eg1: for( int i = 1 ; ; i++ ) separated.
{ Eg1: int a, b;
System.out.println(“infinite loop”); for(a= 1, b= 10 ; a<=5 && b>=1; a++, b-- )
} {
Eg2: for( ; ; ) System.out.println(“Hello Java”);
{ }
System.out.println(“infinite loop”); Note: in loop, multiple conditions can be specified using
} logical operators (&&, || ) only.
Eg3: for( int i = 1 ; i<=10 ; )
System.out.println(“infinite loop”);
Null loop / Empty loop / Bodyless loop / Time Delay loop
A loop that doesn’t include any statement as body of the loop
is called null, delay, empty or bodyless loop. We can use semi
colon after the for loop to make empty loop.
Eg1: for( int i = 1 ; i<1000 ; i++ );

Eg2: for( int i = 1 ; i<1000 ; i++ )


{
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→70
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

While loop
71
While loop is fundamental looping statement. All the expressions are written on separate lines. it is used when the
numbers of iterations are unknown. it is an entry control loop. The condition is checked and the loop executes till a
condition is true.
Syntax: How to get digits from given number:
Eg2: import java.util.*;
initialization Print 10 to 1
while(condition) class GetDigits
int i; {
{ i = 10;
Loop body public static void main()
while(i>=1) {
++/-- {
} Scannner sc = new Scanner(System.in);
System.out.print(i+” “); System.out.println(“Enter a number ”);
i--; int n = sc.nextInt();
Eg1:
} int dig;
Print 1 to 10
int i; while(n!=0) // while(n>0)
i = 1; {
while(i<=10) dig = n%10; // To get last digit
{ n = n/10; // To remove last digit
System.out.Print(i+” “); Note: System.out.println(dig);
i++; }
} }
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→71
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

while loop - Questions


72
Q1→ WAP to input a number and print its factorial using while loop.
Q2→ WAP to input a number and find out the sum of its digits and total digits.
eg. if n = 2543 then sum of digits = 2+5+4+3 = 14, total number of digits = 4
Q3→ WAP to input a number and find out the sum of even and odd of its digits and total of even and odd digits separately.
eg. if n = 25438 then sum of even digits = 2+4+8 = 14, total number of even digits = 3,
sum of odd digits = 5 + 3 = 8, total number of odd digits = 2
Q4→ WAP to input a number of three digits and find out number is Armstrong or not Armstrong number.
(An Armstrong number is number which is equal to the sum of the cube of its digits.)
Example: consider the number 153, Sum of the cube of digits = 1 + 125 + 27 = 153. 153 is Armstrong number)
Q5→ WAP to input a number of any numbers of digits and find out number is Armstrong or not Armstrong number.
Q6→ WAP to input a number and find out reverse number and also check number is palindrome of not.
(A Palindrome number is number which is equal to the its reverse number.)
Example: consider the number 123, reverse number = 321 (123 is not Palindrome number)
Q7→ WAP to input a number and find out maximum or minimum digit.
Q8→ WAP to input starting number, ending number and step value and print series.
Eg. Starting no. = 2, ending no. = 20, step value = 4 then series will be 2, 6, 10, 14,18.
Q9→ WAP to input starting number, number of terms and step value and print series.
Eg. Starting no. = 5, number of terms = 6, step value = 3 then series will be 5, 8, 11, 14,17, 20.
Q10→Write a program to accept a number and check and display whether it is Super Six number or not.
(A Super Six number is number which contains at least two or more sixes.) Example: 2366, 60166 etc.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→72


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

Do…While loop Q2→ WAP to input name and age of persons. Continue the
73
input process according to user’s choices(y/n). Calculate
Do-while loop is an exit controlled loop. It first executes the average age of persons.
statements & then checks the condition. Thus it executes the import java.util.*;
loop at least once. it is used when number of iterations is class User
unknown. {
Syntai public static void main()
initialization Eg2:
{ Scannner sc = new Scanner(System.in);
do int i = 1;
String name; int age, cnt=0, sum=0; char ch;
{ do
do
Loop body {
{
++/-- System.out.print(i+” “);
System.out.println(“Enter a name and age”);
}While(condition); i++;
name = sc.neitLine();
Eg1: }while(i <= 10);
age = sc.neitint();
int i = 1; Output will be: sum = sum + age;
do 1 2 3 4 5 6 7 8 9 10 cnt++;
{ System.out.println(“Do u want to continue(y/n)”);
System.out.print(i+” “); ch = sc.neit().charAt(0);
i++; } while(ch==‘y’ || ch==‘Y’);
}while(i >= 10); Q1→ WAP to input a number System.out.println(“Average age =”+(sum/cnt));
Output will be: and calculate factorial of given }
1 number. }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→73


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 8: Iterative Constructs in Java

Differences & Similarity between loops


74

for loop while loop

It is used when number of iterations are known. It is used when number of iterations is unknown.

All the expressions are written on same lines. All the expressions are written on different lines.

while loop do - while loop

It first checks the condition & then executes the statements. It is used when number of iterations is unknown.

It is entry controlled loop. It is exit controlled loop.

It will not execute if condition is false for first time. It executes once even if the condition is false.

Similarity: Both the loops are used when number of iterations is unknown.

Comparing Do…While and While - The difference between do-while and while is that do-while evaluates its test
expression at the end of the loop instead of at the beginning. Therefore, the statements within the do block are always
executed at least once. Do-while is an exit controlled loop and while is an entry controlled loop.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→74
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

NESTED LOOP
75

A loop placed inside another loop is known as nested Rules to make patterns
loop. For every iteration of outer loop, inner loop
executes for n times. 1) Count total number of rows and columns.
Syntax: 2) Execute Outer loop for Rows and inner loop for Columns.
Outer loop Output
3) Print OUTER loop variable when we have Same values in
{ //outer loop body x y rows like -
inner loop 1 1
{ 1 2 11111
//inner loop body 1 3 22222
} 1 4
} 33333 and set outer loop first then inner loop
Example & Find output: 2 1
System.out.println( “ x y “ ); 4) Print INNER loop variable when we have Different values in
2 2
for(int x = 1 ; x <= 3; x++ ) 2 3 rows like -
{ 2 4
for(int y = 1 ; y <= 4; y++ ) 12345
{ 3 1 12345
System.out.println(x + “ “ + y); 3 2
} 12345 and set inner loop first then outer loop
3 3
System.out.println(); 3 4
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→75
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

Pattern Questions
76

Q1 → 1 1 1 1 1 Q2→ 1 2 3 4 Q3→ ABCDE


2 2 2 2 2 1 2 3 4 ABCDE
3 3 3 3 3 1 2 3 4 ABCDE
4 4 4 4 4 1 2 3 4 ABCDE
1 2 3 4

int x, y ; int x, y ; int x, y ;


for( x = 1; x <= 4; x++ ) for( x = 1; x <= 5; x++ ) for( x = 1; x <= 4; x++ )
{ { {
for( y = 1; y <= 5; y++ ) for( y = 1; y <= 4; y++ ) for( y=1; y<=5; y++ )
{ { {
System.out.print( x ); System.out.print( y ); System.out.print((char) (y+64));
} } }
System.out.println(); System.out.println(); System.out.println();
} } }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→76


Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop Pattern Questions

Q4 → 4 4 4 4 4 4 Q7 → A A A A Q10 → 1 2 3 4 Q13 → 7 7 7 7 7 7 7
77
3 3 3 3 3 3 B B B B 5 6 7 8 6 6 6 6 6 6
2 2 2 2 2 2 C C C C 9 1 2 3 5 5 5 5 5
1 1 1 1 1 1 D D D D 4 5 6 7 4 4 4 4
3 3 3
2 2
1
Q5 → 5 4 3 2 1 0 Q8 → D C B A Q11 → 1 Q14 → 1 1 1 1 1
5 4 3 2 1 0 D C B A 2 2 2 2 2 2
5 4 3 2 1 0 D C B A 3 3 3 3 3 3
5 4 3 2 1 0 D C B A 4 4 4 4 4 4
5 4 3 2 1 0 D C B A 5 5 5 5 5 5

Q6 → @ @ @ @ Q9 → D D D Q12 → 6 Q15 → D
@ @ @ @ C C C 5 5 C C
@ @ @ @ B B B 4 4 4 B B B
@ @ @ @ A A A 3 3 3 3 A A A A
@ @ @ @ 2 2 2 2 2
1 1 1 1 1 1
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→77
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

Pattern Questions
78

Q16 → A B C D Q19 → 7 6 5 4 3 2 1 Q22 → A Q25 → 1 2 3 4 5


E F G H 6 5 4 3 2 1 A B 2 3 4 5
I J K L 5 4 3 21 A B C 3 4 5
M NO P 4 3 2 1 A B C D 4 5
3 2 1 A B C D E 5
Q17 → 1 2 1
1 Q23 → 6 Q26 → 1
1 2 2 3
6 5
1 2 3 Q20 → 1 2 3 4 5 6 5 4 4 5 6
1 2 3 4 1 2 3 4 7 8 9 10
6 5 4 3
1 2 3 4 5 1 2 3 11 12 13 14 15
6 5 4 3 2
1 2 6 5 4 3 2 1
Q18 → 6 1
5 6 Q24 → 5 4 3 21 Q27→ #
4 5 6 Q21 → 1 5 4 3 2 # *
3 4 5 6 2 1 5 4 3 # * #
2 3 4 5 6 3 2 1 5 4 # * # *
1 2 3 4 5 6 4 3 2 1 5 # * # * #
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→78
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop Pattern Questions

Q28 → $ Q31 → 7 7 7 7 7 7 7 Q34 → A Q37 → 7 6 5 4 3 2 1


79
$ $ 6 6 6 6 6 6 A B 6 5 4 3 2 1
$ $ $ 5 5 5 5 5 A B C 5 4 3 2 1
$ $ $ $ 4 4 4 4 A B C D 4 3 2 1
3 3 3 3 2 1
2 2 2 1
1 1
Q29 → 1 Q32 → Q38 →
1 1 1 1 1 Q35 → 1 1 2 3 4 5
2 2 2 2 2 2 1 2 3 4
1 2
3 3 3 3 3 3 1 2 3
1 2 3
4 4 4 4 4 4 1 2
1 2 3 4
5 5 5 5 5 5 1
1 2 3 4 5

Q30 → 6 Q33 → D Q36 → 6 Q39 → 1


5 5 C C 5 6 2 1
4 4 4 B B B 4 5 6 3 2 1
3 3 3 3 A A A A 3 4 5 6 4 3 2 1
2 2 2 2 2 2 3 4 5 6
1 1 1 1 1 1 1 2 3 4 5 6
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→79
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop Pattern Questions

Q40 → A Q43 → 1 2 3 4 5 Q46→ # Q47→ 1


80
B A 2 3 4 5 # * 1 2 1
C B A 3 4 5 # * # 1 2 3 2 1
D C B A 4 5 # * # * 1 2 3 4 3 2 1
E D C B A 5 # * # * # 1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1

Q41 → 6 Q44 → 9 8 7 6 Q48→ 1


6 5 5 4 3 1 2 1
6 5 4 2 1 1 2 3 2 1
6 5 4 3 0 1 2 3 4 3 2 1
6 5 4 3 2 1 2 3 4 5 4 3 2 1
6 5 4 3 2 1 1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 4 3 2 1
Q42 → 5 4 3 21 Q45 → 1 3 5 7 9 1 2 3 4 3 2 1
5 4 3 2 3 5 7 9 1 1 2 3 2 1
5 4 3 5 7 8 1 3 1 2 1
5 4 7 9 1 3 5 1
5 9 1 3 5 7
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→80
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop Pattern Questions

Q49 → B Q52 → BLUEJ Q55 → B Q58 → BLUEJ


81
BL BLUE BL BLUE
BLU BLU BLU BLU
BLUE BL BLUE BL
BLUEJ B BLUEJ B

Q50 → B Q53 → BBBBB Q56 → B Q59→ BBBBB


LL L L LL LL L L LL
UUU UUU UUU UUU
EEEE EE EEEE EE
J JJ JJ J JJ J JJ J

Q51 → B Q54 → BEULB Q57 → B Q60 → BEULB


LB EUL B LB EULB
ULB ULB ULB ULB
EULB LB EULB LB
JEULB B JEULB B
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→81
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

Series Questions Q61 → 1


82 01
Print the following series. 010
Q1 → 0, 1, 2, 3, 6, 11, ……………………….n terms. 1010
Q2 → 1, 2, 4, 7, 11, 16, ………………………n terms.
10101

Q3 → 2, 22, 222, 2222, ………………………10 terms.


Q4 → 3, 5, 7, 11, 13, 17, 19, …………………n terms.
Find sum of the following series.
Q5 → 1! + 2! + 3! + 4! + 5! + 6! + . . . . . . . . . . .n!.
Q6 → 11 + 32 + 53 + 74 + 95 . . . . . . . . . . N terms.
Q7 → 11/2! + 22/4! + 33/6! . . . . . . . . . . . N terms.
Q8 → 1 + 1 + 2 + 3 + 5 + ………………. To N terms.
Q9 → 0 – 3 + 8 – 15 + …………………….to 10 terms.
Q10 → 1 + (1+2) + (1+2+3) + (1+2+3+4) + ……..(1+2+3+4+……n).
Q11 → 1 + (1+2)/2! + (1+2+3)/3! + . . . . . . . . (1+2+3+4+……n)/n!.
Q12 → a1 – a3 + a5 – a7 + ……………............ To N terms.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→82
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop


Jump Statements - break & continue statement
83
break→
Break statement is used to exit from loop. Break statement will ignore the execution of statements used after break
statement in a loop. If break statement is found in inner loop then it terminates the inner loop only. Syntax→ break
Eg1: Eg2: Eg3:
for(int i=1;i<10;i++) for(int i=1; i<5; i++) for(i=1; i<10; i++)
{ { {
if(i>=5) for(int j=1; j<10; j++) System.out.print(i, “ ”);
break; { if(j>=5) break;
System.out.print(i+“ ”); break; }
} System.out.print(j, “ ” );
Output ___________ } Output ___________
} Output __________
continue statement→
It is used to continue with the next iteration value of the loop. Continue statement will ignore the execution of statements
used after continue statement in a loop. Continue statement cannot be used in switch. Syntax – continue
Eg1: for(int i=1; i<=10; i++) Eg2: for(int i=1;i<11;i++)
{ {
if(i>=5 and i<=8): System.out.print(i+“ ”);
continue; continue;
System.out.print(i+“ ”); }
} Output _________ Output _______________
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→83
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

Find Outputs
84

Q1→ for( i = 1; i <= 10; i++); Q4→ for( i = 1; i <= 20; i++)
System.out.print(i+” “); {
switch(i)
Output _________________ {
case 1: i += 3;
Q2→ int c = 0; case 2: i += 5; break;
for( i = 1; i <= 45; i++) default: i += 2;
{ }
c++; System.out.print( i + ” “);
} }
System.out.print(i+“ ”+c); output_________________

output__________________
Q5→ int s=0, k=10;
Q3→ int i = 1; do
while(i<=10) {
{ System.out.print( k + ” “);
System.out.print( i + ” “); s = s+5;
i++; }while(k<=20);
} output __________ A4→
output __________ 9 12 15 18 21
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→84
Ch1: Revision of class 9th Sub: Computer Application
JMD HGGM
ICSE Class 10th

Unit 9: Nested Loop

85

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→85


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

86 Ch_no. Topics Page No.

2. Library classes
1. Character functions
2. Conversion methods
3. Auto boxing & Unboxing
4. Programs

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→86


Ch 2 : Library Classes Sub: Computer Application
JMD HGGM
ICSE Class 10th

Methods / Functions

1. Pre-Defined Function → Functions/Methods which are pre-defined in ‘JAVA’ language.


87
Examples → pow(), abs(), length(), toUpperCase(), etc.
There are three types of pre-defined java functions.
1. Character methods, 2. String methods, 3. Math Methods.
1. Character methods:
Character.isLetter() → method checks whether a character is a letter/alphabet or not.
Syntax → boolean Character.isLetter( char )
Argument
Return Type
Wrapper Class Method Name

Exercise: Outputs
Eg: → boolean b; Outputs
boolean b;
b = Character.isLetter(‘y’); char ch1 = ‘*’, ch2 = ‘D’ ;
System.out.print(b); b = Character.isLetter(ch1);
System.out.print(b);
b = Character.isLetter(‘5’);
System.out.print(b); b = Character.isLetter(ch2);
System.out.print(b);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→87


Ch 2 : Library Classes Sub: Computer Application
JMD HGGM
ICSE Class 10th

Character Methods / Functions

Character.toUpperCase() → Method returns a character in upper case.


88

Character.toLowerCase() → Method returns a character in lower case.

Syntax → char Character.toUpperCase( char )

Argument
Wrapper Class Method Name
Return Type

Outputs Eg2: Outputs


Eg1:→ char b;
char b, ch1 = ‘g’, ch2 = ‘M’ ;
b=Character.toUpperCase(‘e’);
b=Character.toUpperCase(ch1);
System.out.print(b);
System.out.print(b);
b=Character.toLowerCase(‘E’);
b=Character.toLowerCase(ch2);
System.out.print(b);
System.out.print(b);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→88


Ch 2 : Library Classes Sub: Computer Application
JMD HGGM
ICSE Class 10th

Character Methods / Functions

SYNTAX OF FUNCTION EXAMPLE


89

1. boolean Character.isLetter(char) boolean b = Character.isLetter(‘y’)

2. boolean Character.isDigit(char) boolean b = Character.isDigit(‘5’)


Note:
Any
3. boolean Character.isLetterOrDigit(char) boolean b = Character.isLetterOrDigit(‘E’) method
start with
4. boolean Character.isWhitespace(char) boolean b = Character.isWhitespace(‘ ‘) word ‘is’
that return
5. boolean Character.isUpperCase(char) boolean b = Character.isUpperCase(‘M’) always
6. boolean Character.isLowerCase(char) boolean b = Character.isLowerCase(‘m’) boolean
value.
7. char Character.toUpperCase(char) char ch = Character.toUpperCase(‘y’)

8. char Character.toLowerCase(char) char ch = Character.toLowerCase(‘P’)

Wrapper Class Argument


Return Type Method name true
boolean
false

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→89


Ch 2 : Library Classes Sub: Computer Application
JMD HGGM
ICSE Class 10th

character Questions.

Q1→Character conversion into Opposite Case. Q2→WAP to input a character and check it is symbol or not.
90

import java.util.Scanner; import java.util.Scanner;


class Case_conversion class Case_conversion
{ {
public static void main() public static void main()
{ {
Scanner sc = new Scanner (System.in); Scanner sc = new Scanner (System.in);
System.out.println("Enter a character "); System.out.println("Enter a character ");
char ch = sc.next().charAt(0); char ch = sc.next().charAt(0);
if(Character.isUpperCase(ch)) if( !Character.isLetterOrDigit(ch) )
{ {
ch = Character.toLowerCase(ch); System.out.print(“It is symbol”);
} }
else if(Character.isLowerCase(ch)) else
{ {
ch = Character.toUpperCase(ch); System.out.print(“It is not symbol”);
} }
System.out.print( ch ); }
}
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→90


Ch 2 : Library Classes Sub: Computer Application
JMD HGGM
ICSE Class 10th

91

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→91


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

92 Ch_no. Topics Page No.

3. Array in java

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→92


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array In Java
➢ Array is a collection of data having homogenous (similar) data Input data in array using scanner class
93
type values. Scanner sc = new Scanner (System.in);
➢ Continuous memory is allocated for array. int ar[ ] = new int[5];
There are two types of array for(int i = 0; i <= 4; i++)
1. Single Dimensional array (1 D Array) {
2. Two / Multi-Dimensional array (2 D Array) System.out.println("Enter data ");
ar[i] = sc.nextInt();
1. Single Dimensional array (1 D array)
}
Syntax: datatype arrayname[ ] = new datatype[size] ; Or
Printing an array elements
datatype [ ] arrayname = new datatype[size] ;
for(int i = 0; i <= 4; i++)
Eg: int ar[ ] = new int[5]; //20 bytes
{
double b[ ] = new double[5]; //40 bytes
System.out.println(ar[i] + “ ”);
char c[ ] = new char[5]; //10 bytes
}
Initialization of 1 Dimensional array
int ar[ ] = { 10, 20, 30, 40, 50}; Input data in array using BufferedReader class
double b[ ] = { 5.6, 10.45, 6.7, 8.5, 9.66}; BufferedReader br = new BufferedReader( new
char ch[ ] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’}; InputStreamReader (System.in));
String st[ ] = {“abc”, “xyz”, “aaa”}; ar[0] int ar[ ] = new int[5];
for(int i = 0; i <= 4; i++)
{
ar[ ]= 10 20 30 40 50 Array Index no./
System.out.println("Enter data ");
name subscript no.
ar[0] ar[1] ar[2] ar[3] ar[4] ar[i] = Integer.parseInt( br.readLine() );
It always starts
}
from zero(0)
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→93
Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Basic Structure Of Array Question - Answer

import java.util.*; // Printing array elements


94 class Array1 for (int i = 0; i < n; i++)
{ {
public static void main() System.out.println( a[ i ] );
{ }
Scanner sc = new Scanner(System.in); Q1→ WAP to input 10 elements in an array and print array.
System.out.println("Enter total number of elements"); A→ import java.util.*;
int n = sc.nextInt(); class Array1
// Array declaration {
int a[ ] = new int [n]; public static void main()
// Array Input {
for ( int i = 0; i < n; i++) Scanner sc = new Scanner(System.in);
{ int a[ ] = new int [10];
System.out.println("Enter data"); for ( int i = 0; i < 10; i++)
a[i] = sc.nextInt(); {
} System.out.println("Enter data");
for (int i = 0; i < n; i++) a[i] = sc.nextInt();
{ }
//calculation code will come here for (int i = 0; i < 10; i++)
// according to given program { System.out.println( a[ i ] ); }
} } }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→94


Ch 3: Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Questions
Q1→ WAP to input 10 elements in an array and print array.
95 Q2→ WAP to input 5 numbers in an array and find sum and average of array elements.
Q3→ WAP to input 5 or N numbers in an array and find product of even numbers of array elements.
Q4→ WAP to input 5 numbers in an array and copy these numbers in another array.
Q5→ WAP to input 5 numbers in an array and reverse these numbers in another array.
Q6→ WAP to input 5 numbers in an array and reverse these numbers in same array.
Q7→ WAP to input 5 or N numbers in an array and find out maximum and minimum number.
Q8→ WAP to input 5 numbers in an array and find out standard deviation.
Q9→ Write a program to accept the year of graduation from school as an integer value from the user. Using the Binary
Search and linear Search technique on the sorted array of integers given below, output the message “record exists” if
the value input is located in the array. If not, output the message “Record does not exist”.
{1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010}
Q10→ Write a program to accept name and total marks of N number of students in two single subscript array name[ ] and
totalmarks[ ]. Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average. [deviation = total marks of a student – average]
Q11→ Write a program to input integer elements into an array of size 20 and perform the following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array. (iv) Display product of all odd elements of the array.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→95


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Question - Answer


Q2→ WAP to input N/10 numbers in an array and find sum and average of array elements.
96 A2→ import java.util.*; import java.util.*;
class Array1 class Array1
{ {
public static void main() public static void main()
{ {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
System.out.println("Enter total number of elements"); nt a[ ] = new int[10];
int n = sc.nextInt(); for(int i=0; i<10;i++)
int a[ ] = new int [n]; //int a[ ] = new int[10]; {
for ( int i = 0; i < n; i++) //for(int i=0; i<10;i++) System.out.println("Enter data");
{ a[i] = sc.nextInt();
System.out.println("Enter data"); }
a[i] = sc.nextInt(); int sum = 0; double avg;
} for(int i=0; i<10;i++)
int sum = 0; double avg; {
for (int i = 0; i < n; i++) //for(int i=0; i<10;i++) sum = sum + a[ i ];
{ }
sum = sum + a[ i ]; avg = sum/n;
} System.out.println(“sum =”+sum );
avg = sum/n; System.out.println(“average =”+avg );
System.out.println(“sum =”+sum ); }
System.out.println(“average =”+avg ); } } //End of class } //End of class
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→96
Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Question - Answer

Q5→ WAP to input 5 numbers in an array and reverse these numbers in another array.
97

A5→ import java.util.*;


class Array4 System.out.println(“reverse array is ” );
{ for (int i = 0; i < n; i++)
public static void main() {
{ System.out.print( ar[ i ] + “ ”);
Scanner sc = new Scanner(System.in); }
System.out.println("Enter total number of elements"); }
int n = sc.nextInt(); } //end of class
int a[ ] = new int [n];
int ar[ ] = new int [n];
for ( int i = 0; i < n; i++)
{
System.out.println("Enter data");
a[i] = sc.nextInt();
}
for (int i = 0; i < n; i++)
{
ar[ n-1-i ] = a[ i ];
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→97


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Questions

Q12→ Write a program to input twenty names in an array. Arrange these names in descending order of alphabets,
98
using the bubble sort technique and selection sort technique. Print the sorted array.

Q13→ Write a program to initialize the seven wonders of the World along with their Locations in two different arrays.
Search for a name of the country input by the user. If found, display the name of the country along with its Wonder,
otherwise display “Sorry Not Found!”.
Seven wonders – CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU
PICCHU, PETRA, COLOSSEUM.
Location - MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example - Country Name : INDIA Output : INDIA – TAJMAHAL
Country Name : USA Output : Sorry Not Found!

Searching in Array→ There are 2 types of searching


1) Linear Search
2) Binary Search

Sorting in Array → There are 2 types of sorting in array


1) Bubble sort
2) Selection sort

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→98


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Linear Search

Q→ WAP to input N numbers in an Array and find key element and also print index number. (Q9)
99

A→ import java.util.*;
public class Linear_Search
{ for( i = 0; i<n; i++)
public static void main() {
{ // Array Input String key; if(key == arr[ i ]) //if(key.equals(arr[i])==true)
int n, key, i, flag=0 ; {
Scanner sc = new Scanner(System.in); flag = 1;
System.out.println("Enter total number of elements of array:"); break;
n = sc.nextInt(); }
int arr[ ] = new int[n]; // String arr[] = new String[n]; } //end of while loop
for(i = 0; i < n; i++) if(flag == 1)
{ {
System.out.println("Enter array number :"); System.out.print(key+“ Number is found at ”+i);
arr[i] = sc.nextInt(); // arr[i] = sc.nextLine(); }
} else
{
System.out.println("Enter number to be searched :"); System.out.print(“Number is not found”);
key = sc.nextInt(); // key = sc.nextLine(); }
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→99
Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Binary Search

import java.util.*; (Q9) while(li <= ui)


100
public class Binary_Search {
{ mid = (li + ui)/2;
public static void main() if(key < arr[mid]) // if( key.compareTo(arr[mid])<0)
{ // Array Input {
int n, key, i; // String key ui = mid - 1;
Scanner sc = new Scanner(System.in); }
System.out.print("Enter total no. of elements of array:"); else if(key > arr[mid]) //else if( key.compareTo(arr[mid])>0)
n = sc.nextInt(); {
int arr[] = new int[n]; // String arr[] = new String[n]; li = mid + 1;
}
for(i = 0; i<n; i++) else if(key == arr[mid]) // if( key.compareTo(arr[mid])==0)
{ {
System.out.println("Enter array number :"); flag = 1;
arr[i] = sc.nextInt(); // arr[i] = sc.nextLine(); break; }
} } //end of while loop
if(flag == 1)
System.out.println("Enter number to be searched :"); { System.out.print(“Number is found”); }
key = sc.nextInt(); // key = sc.nextLine(); else
int li = 0, ui = n-1, mid, flag=0; { System.out.print(“Number is not found”); } } }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→100


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Program of Sorting of numeric & string array using bubble sort

Q→ WAP to input N numbers in an Array and sort array in ascending order. (Using bubble sort). (Q12)
101

A→ import java.util.*;
public class Bubble_sort int temp; //String temp
{ for ( i = 0; i < n-1; i++)
public static void main() {
{ for ( j = 0; j < (n-1-i); j++)
int n, i, j; {
Scanner sc = new Scanner(System.in); if(arr[ j ] > arr[ j+1 ]) //if( arr[ j ].compareTo(arr[ j+1 ])>0)
System.out.print("Enter total number of element of array"); {
n = sc.nextInt(); temp = arr[ j ];
arr[ j ] = arr[ j+1 ];
int arr[] = new int[n]; //String arr[] = new String[n]; arr[ j+1 ] = temp;
}
for(i = 0; i<n; i++) }
{ }
System.out.println("Enter array number :"); System.out.println("sorted array is ");
arr[i] = sc.nextInt(); // arr[i] = sc.nextLine(); for ( i = 0; i < n; i++)
} {
System.out.println(arr[ i ]+ “ “ );
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→101


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Selection Sort

Q→ Write a program to input twenty names in an array. Arrange int max = 0, index = 0; //String max
102
these names in descending order of alphabets, using the bubble sort for ( i = 0; i < n-2; i++)
technique and selection sort technique. Print the sorted array. (Q12) {
max = arr[ i ];
import java.util.*; for ( j = i+1; j < (n-1); j++)
public class Selection_sort {
{ if(arr[ j ] > max) // if( arr[ j ].compareTo(max)>0)
public static void main() {
{ max = arr[ j ] ;
int n, i; index = j ;
Scanner sc = new Scanner(System.in); }
System.out.print("Enter total number of element of array"); }
n = sc.nextInt(); arr[ index ] = arr[ i ];
arr[i] = max;
int arr[] = new int[n]; //String arr[] = new String[n]; }
System.out.println(“Sorted Array is ");
for(i = 0; i<n; i++) for ( i = 0; i < n; i++)
{ {
System.out.println("Enter array number :"); System.out.println(arr[ i ]+ “ ”);
arr[i] = sc.nextInt(); // arr[i] = sc.nextLine(); }
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→102


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Theory Points

Array is a group of elements of same type. It is stored in a Length property:


103 contiguous memory location Length property is used to get total number of elements
of an array. It returns the size of the array.
Advantage: Eg. int a[] = {1, 4, 3, 2, 7};
➢ It can store many values under a single name. int len = a.length; // 5 (counts from 1.)
➢ Every element can be accessed by its index using for loop.
➢ Searching and sorting of elements is easier. Name the error which is caused when the specified
position exceeds the last index of an array.
Dis-advantage: Error arised is ArrayIndexOutOfBoundException.
➢ It can store value of one data-type only. Eg. int a[] = {2, 4, 6, 3, 2, 7};
➢ Length of the array is fixed. System.out.print(a[5]); //index 5 is not available.

Subscript/index number Two types of array:


Index number/subscripts are positions of each element of the 1. Single Dimension Array: The element in single
array, to allow the program to access an individual element of dimension array is accessed by single subscript.
the array. It begins with zero and end at length-1. Eg. Int a[] = new int[10];
2. Multi Dimension Array: The elements in multi
Subscripted variable dimension array are accessed by 2 subscripts.
Subscripted variable is a symbolic name for an array of Eg. Int a[][]=new int[2][3]; //2 rows & 3 columns.
variables whose elements are identified by subscripts.
Eg: a[0]=20; a is subscripted variable and 0 is subscript. 10 20 30
40 50 60
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→103
Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array Theory Points

Linear Search:
Name the search or sort algorithm that:
104 The item is compare one by one with each element in an
a. Makes n-1 passes to sort the whole array checking the
array, which traverses sequentially to locate the item. It is
adjacent elements in every pass. Bubble Sort
time consuming for large no. of elements. Array need not
b. Compare the sought key with each key element of the
be sorted.
array. linear Search
The range of an array with 10 elements.
Binary Search:
Range of array is from 0 to (length of array – 1), i.e. 0 to 9.
The array has to be in sorted order. The array is divided
Sorting
into two halves and the middle element is compared. If the
Bubble Sort:
search value is not located on middle element then either
In bubble sort the adjacent elements are compared. For
of the two halves is checked depending upon the search
ascending order if the element is greater than it is
value. It is the faster processes for large no. of elements.
interchanged (swapped) with the adjacent element. This
process is repeated for all the elements for n-1 times. It goes
Array Instantiation
through all the loop cycles even if the array is sorted much
To instantiate (or create) an array, write the new keyword,
before.
followed by the square brackets containing the number of
Selection Sort:
elements you want the array to have.
The maximum or minimum value is found and is swapped
int ages[] = new int[100];
with the first element of the array, the same process is
repeated for 2nd , 3rd element and so on. It is faster than
You can also instantiate an array by directly initializing it
Bubble sort.
with data. For example: int arr[] = {1, 2, 3, 4, 5};

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→104


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Exercise - Find the outputs:

Q1: Q2: Write java statements for the following


105 a) int ar[ ] = {1, 2, 3, 4, 5}; a) Initialise char A[] with vowels in the English language.
int i = 2;
ar[i] += ar[i++] + 1 - ++ar[i-1]; Q3: Give the values that will be stored in myArr and k after you
for(i=1; i<=3; i++) invoke mystery(myArr,k), Where myArr, k, and mystery() are
System.out.println( ar[i] + “,” ); declared as follows:
int myArr[]={1,2,3,4,5};
b) String x[ ] = { “Hello”, “Word” }; int k = 3;
System.out.println( x[1].length() ); void mystery(int a[], int m)
System.out.print( x.length ); {
++a[m];
c) double a[]={2.93, 4.65, 3.12, 9.0, 6}; --m;
for(int s = 0; s <= 4; s++) }
{
a[s] += 5; Q4: The following numbers: (89,20,31,56,25,64,48) are to be
System.out.println(a[s]); sorted using selection sort. The Array Elements after the 1st
} iteration : ( 20,89,31,56,25,64,48). Show the array elements
after the second iteration.
d) Find out the number of bytes required to store
byte B[20]

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→105


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array output Questions

Q5: What will this code print ? [2] Q11: What is the difference between the linear search and the
106 int arr[] = new int[5]; binary search technique? [2]
System.out.println(arr); Q12: String x[] = {“Artificial intelligence”, “IOT”, “Machine learning”,
“Big data”};
(i) 0 (iii) 0000
Give the output of the following statements:
(ii) value stored in arr[0] (iv) garbage value (i) System.out.println(x[3]);
(ii) System.out.println(x.length);
Q6: If int x[] = {4, 3, 7, 8, 9,10};
what are the values of p and q ? [2]
Q13: What will this code print ? [2]
(i) p = x.length int arr[] = new int[5];
(ii) q = x[2] + x[5] * x[1] System.out.println(arr[0]);
Q7: Name any one reference data type. [2] (i) 0 (iii) 0000
Q8: String x[] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”, (ii) value stored in arr[0] (iv) garbage value
BLACKBERRY};
Give the output of the following statements: [2]
(i) System.out.println(x[1]); Q14: If int x[] = {4, 3, 7, 8, 9,10};
(ii) System.out.println(x[3].length()); what are the values of p and q?
Q9: Differentiate between searching and sorting? (i) p = x[1] % x[0] + ++x[3] * x[3] / x[5]++
Q10: Consider the following String array and give the output. (ii) q = x[2] + x[5] / x[1] * x[2]
String arr[] = {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”,
“JAIPUR”};
System.out.println(arr[0].length()>arr[3].length());
System.out.print(arr[4].substring(0,3);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→106


Ch 3 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

Array output Questions

Q15: String x[] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”}; [2]
107
Give the output of the following statements:
(i) System.out.println(x[2].length());
(ii) System.out.println(x[3].substring(2, x.length);

Q16: Consider the following String array and give the output. [2]
String arr[] = {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
System.out.println(arr.length != arr[0].length());
System.out.print(arr[3].replace(‘N’, ‘m’));

Q17: String x[] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”,BLACKBERRY};


Give the output of the following statements: [2]
(i) System.out.println(x[1].toLowerCase());
(ii) System.out.println(x[3].substring(x.length));

Ans→ 1) a) 2, 3, 4,
3) value of arr are 1,2,3,5,5
value of k is 3
1 4) p = 11 q=28

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→107


Ch 4 : Arrays in Java (1d & 2d) Sub: Computer Application
JMD HGGM
ICSE Class 10th

108

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→108


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

109 Ch_no. Topics Page No.

4. String Handling

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→109


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

STRINGS IN JAVA

String is a set of characters in java.


110

String initialization H e l l o J a v a .
str =
String str = "Hello Java.";
0 1 2 3 4 5 6 7 8 9 10
Character initialization
char ch = ‘A’; index / subscript number
It is always starts from zero (0)

Character String
A character is a single alphabet, a digit or a single String is a set of characters in java.
special symbol. It is primitive datatype. It is non-primitive datatype.
It must have only one character. It encloses within single It encloses within double quotes.
inverted quotes.
Eg : Characters → 'A' , 'i' , '5' , '=' , ‘$‘, etc. Eg: Strings → “Hello Java.”, “computer1”, etc.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→110


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

How to input Strings

String & character input using scanner String & character input using BufferedReader
111

import java.util.Scanner; import java.io.*;


class Str_input
class Str_input
{
{ public static void main() throws IOException
public static void main() {
{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner (System.in); System.out.println("Enter a String ");
System.out.println("Enter a String "); String str = br.readLine();
str = sc.nextLine(); System.out.println("Enter a character ");
str = sc.next() char ch = (char)br.read();
System.out.println("Enter a character "); }
char ch = sc.next().charAt(0); }
} Note:
} readLine() → It is a method which helps to get a string at run time using object
of BufferedReader class.
read() → It is used to get a character from keyboard but it returns ASCII
→ nextLine() used to get sentence/string. value of a inputted character at run time.
Character ASCII Code
→ next() used to get word. A to Z 65 to 90
A to z 97 to 122
→ next().charAt(0) used to get characters.
0 to 9 48 to 57
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→111
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Methods / Functions

SYNTAX OF FUNCTION EXAMPLE


112

String s1 = “Yp”, s2 = “Comp”, s3;


1. String concat(String s)
s3 = s1.concat(s2); sop(s3); // s3 = “YpComp”
String s1 = “yp comp”;
2. String toUpperCase()
s1 = s1.toUpperCase(); sop(s1); // s1 = “YP COMP”
String s1 = “YP COMP”;
3. String toLowerCase()
s1 = s1.toLowerCase(); sop(s1); // s1 = “yp comp”
String s1 = “ JAVA ”;
4. String trim()
s1 = s1.trim(); sop(s1); //s1=“JAVA”
String s1 = “YPCOMPUTER”;
5. String substring(int bi) Y P C O M P U T E R
s1 = s1.substring(5); sop(s1); //s1=“PUTER”
String s1 = “YPCOMPUTER”; 0 1 2 3 4 5 6 7 8 9
6. String substring(int bi, int li)
s1 = s1.substring(2, 7); sop(s1); // s1 = “COMPU”
String s = “java”;
7. String replace(char oldc, char newc)
s = s.replace(‘a’, ‘i’); sop(s); //s = “jivi”

8. String valueOf(all num type) int a=10; String s = String.valueOf(a); //s = “10”

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→112


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Methods

SYNTAX OF FUNCTION EXAMPLE


113

String s=“yp comp.”; int len;


9. int length()
len = s.length(); sop(len); // len = 8
10. int indexOf(char ch) String s=“computer”; int p=s.indexOf(‘m’); sop(p); // p = 2
11. int indexOf(char ch, int i) String s=“malayalam”; int p=s.indexOf(‘a’, 3); sop(p); // p = 3
12. int lastIndexOf(char ch) String s=“malayalam”; int p=s.lastIndexOf(‘a’); sop(p); // p = 7
String s1 = “camp”, s2 = “champ” ; int d;
d = s1.compareTo(s2); sop(d); // d = -7
13. int compareTo(String s1, String s2) if strings are equal then it returns zero (0).
Sop(“computer”.compareTo(“comp”)); // 4
Sop(“comp”.compareTo(“computer”)); // -4
14. char charAt(int n) String s = “computer”; char ch = s.charAt(2); //ch = ‘m’
boolean b; String s1 = “Camp”, s2 = “Comp”;
15. boolean equals(String s)
b = s1.equals(s2); sop(b); // b = false
boolean b; String s1 = “comp”, s2 = “Comp”;
16. boolean equalsIgnoreCase(String s)
b = s1.equalsIgnoreCase(s2); sop(b); // b = true

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→113


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Methods

114
SYNTAX OF FUNCTION EXAMPLE
boolean b; String s1 = “Computer”, s2 = “Comp”;
17. boolean startsWith(String s)
b = s1.startsWith(s2); sop(b); // b = true
boolean b; String s1 = “Computer”, s2 = “ter”;
18. boolean endsWith(String s)
b = s1.endsWith(s2); sop(b); // b = true

Other examples → String str = “Hello Java.”


System.out.println( str.substring(6, 6) ); → No Errors but it won’t print any thing
System.out.println( str.substring(6, 4) ); → Runtime Error StringIndexOutOfBoundsException
System.out.println( str.substring(12) ); → Runtime Error StringIndexOutOfBoundsException
System.out.println( str.charAt(12) ); → Runtime Error StringIndexOutOfBoundsException

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→114


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

Master Program – based on chars


Master program to get characters from string
115 import java.util.Scanner;
public class GetChars
{
public static void main()
{
Scanner sc = new Scanner (System.in);
int i, len;
char chr;
System.out.println("Enter a String ");
String str = sc.nextLine();
len = str.length();
for( i = 0; i < len; i++)
{
chr = str.charAt(i);
/*
* This is the area where we can write the code
* according to given programs. */
System.out.println(chr);
}
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→115
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Questions - based on Characters.

116
Q1 → WAP to input a string and find out its length and print all characters in vertical order and also print their ASCII values
of every character.
Q2 → WAP to input two strings and concatenate it in to third string without using function.
Q3 → WAP to input two strings and concatenate second string at the end of first string.
Q4 → WAP to input a string and reverse it in another string. Eg. s=“abc”; rev=“cba”;
Q5 → WAP to input a string and check whether it is palindrome string or not.
Q6 → WAP to input two strings and compare these two strings. If both strings are same then print strings are equals
otherwise print Strings are unequal.
Q7 → Write a program in Java to accept a string in lower case and change the first letter of every word to upper case.
Display the new string. (2018)
Sample input: we are in cyber world
Sample output: We Are In Cyber World
Q8 → Write a program to accept a sentence and print only the first letter of each word of the sentence in capital letters
separated by a full stop.
Example : INPUT SENTENCE : “This is a cat” OUTPUT : T.I.A.C.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→116
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Programs – based on chars

Q8→ Write a program to accept a sentence and print only the first letter of each word of the sentence in capital
117 letters separated by a full stop. Example: INPUT SENTENCE : “This is a cat” OUTPUT : T.I.A.C.
import java.util.Scanner;
public class GetChars String Programs – based on chars
{
public static void main() Q9 → Special words are those words which starts and ends with
{ the same letter. Examples: EXISTENCE, COMIC, WINDOW
Scanner sc = new Scanner (System.in); Palindrome words are those words which read the same from left
String str; to right and vice-versa.
int i, len; Examples: MALAYALAM, MADAM, LEVEL, ROTATOR, CIVIC
char chr; All palindromes are special words, but all special words are not
System.out.println("Enter a String "); palindromes.
str = sc.nextLine(); Write a program to accept a word check and print whether the
len = str.length(); word is a palindrome or only special word.
str = “ ” + str;
for( i = 0; i < len; i++) Q10→ Write a program in java to accept a string and change the
{ case of each character of the string and display the new string.
chr = str.charAt(i); Sample input : WelComE TO School
if( chr == ‘ ’ ) Output : wELcOMe to sCHOOL
{
chr = str.charAt(i+1);
System.out.println(Character.toUpperCase(chr)+“.”);
}
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→117
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Programs – based on chars

Q11→
118 a) Write a program to accept a String. Convert the string to Uppercase. Count and output the number of double letter
sequences that exist in the string.
Sample input : “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output : 4
b) Write a program to accept a String and convert its into its Piglatin form.To translate word into a Piglatin word, convert
the word into Uppercase and then 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 towards the end followed by “AY”
Sample Input (1) : London, Sample output (1) : ONDONLAY
Sample Input (1) : Olympics, Sample output (1) : OLYMPICSAY

Q12→Write a program to assign a full path and file name as given below. Using library functions, extract and output the
file path, file name and file extension separately as shown.
Input: c:\users\admin\Pictures\flower.jpg
Output Path : c:\users\admin\Pictures\
File name : flower
Extension : jpg

Q13→Write a program to input a sentence from user and print every alternative characters (leaving space, vowel and
numbers) of it (starting from first character).
e.g; Sample Input : DISARI PUBLIC SCHOOL, HALDIA – 22 Sample output: DSRLCSHLI-
(Note: all alternate characters are underlined, output contains all of them except space, vowel and numbers).

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→118


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Programs – based on chars

Q12→ Write a program to assign a full path and file name as given below. Using library functions, extract and output the file
119
path, file name and file extension separately as shown. Input: c:\users\admin\Pictures\flower.jpg
Output: Path: c:\users\admin\Pictures\ File name: flower Extension: jpg
A12→ import java.util.Scanner;
public class GetChars
{ Hints:
public static void main() A11 a) A11 b)
{ for( i = 0; i < len; i++) str = str.toUpperCase();
Scanner sc = new Scanner (System.in); { chr1 = str.charAt(i); for( i = 0; i < len; i++)
String str, path = “”, fname=“”, ext=“”; chr2 = str.charAt(i+1); {
System.out.println("Enter a String "); if( chr1 == chr2 ) ch = str.charAt(i);
str = sc.nextLine(); { if(ch==‘A’||ch==‘E’||ch==‘I’||ch==‘O’||ch==‘U’)
ind = str.lastIndexOf(‘\’); cnt++; break;
path = str.substring(0, ind+1); i++; }
dot_ind = str.indexOf(‘.’); } str1 = str.substring(0, i);
fname = str.substring(ind+1, dot_ind+1); } str2 = str.substring(i);
ext = str.substring(dot_ind+1); nstr = str1 + str2 + “AY”;
System.out.println(“Path: “ + path); Sop(nstr);
System.out.println(“File name: “ + fname);
System.out.println(“Extension: “ + ext);
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→119
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Programs – based on chars

Q14→ Write a program to arrange the letters of string in alphabetically order and print the new string. Any
120
character that is Not a part of the alphabet are added at the end of the new string.
E.g: if the input is “@Computer Application 2019”,
then the output is “aAcCeiilmnooppprttu@ 2019”. [Note that there is 2 spaces after @ in output string]

A14→ import java.util.Scanner;


public class Arrange_Letters
for( x = ‘A’; x <= ‘Z’; x++)
{
{
public static void main() for( i = 0; i < len; i++)
{ { chr = str.charAt(i);
Scanner sc = new Scanner (System.in); if( Character.isLetter(chr))
String str, nstr=“”, nstr1=“”; {
int i, len; if(Character.toUpperCase(chr) == x)
nstr = nstr + chr;
char chr, x;
}
System.out.println("Enter a String "); else
str = sc.nextLine(); nstr1 = nstr1 + chr;
len = str.length(); }
}
System.out.println(nstr + nstr1);
} }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→120
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Programs – based on chars

Q15→ Write a program to input any given string to calculate the total number of characters and vowels present in the
121
string and also reverse the string:-
Example : input a string : SNOWY
output
Total number of characters : 05
Number of Vowels : 01
Reverse string : YWONS

Q16→Write a program that asks the user to enter a sentence, and to print the sentence in reverse order, with the
case of each letter reversed. Eg:

Q17→WAP to input a string and find total number of capital, small alphabet, number or symbol.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→121


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

Master program - based on words.

Master program to get words from sentence


122

import java.util.Scanner;
public class GetWords
{
public static void main()
{ for( i = 0; i < len; i++)
Scanner sc = new Scanner (System.in); {
String str, wrd = ""; chr = str.charAt(i);
int i, len; char chr; if(chr != ' ')
System.out.println("Enter a String "); { //hello java program
str = sc.nextLine(); wrd = wrd + chr;
str = str + " "; }
len = str.length(); else
{ /*This is the area
* where we can write the code
* according to given programs. */
System.out.println(wrd);
wrd = "";
}
} // End of for loop
} // End of main()
} // End of class()
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→122
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String programs - based on words.

Q1→ WAP to input a sentence and print all words in vertical order.
123

Q2→ WAP to input a sentence and print all words in vertical order, serial no of words, total no. of character of words
and count the vowels of every word separately with following headings.
Sno. word word length Total vowels
---- ------ --------------- ----------------
Q3→ WAP to input a sentence and print all words in reverse order.
Q4→ WAP to input a sentence and print all palindrome words.
Input: MOM AND DAD ARE LEARNING MALAYALAM
Output: MOM DAD MALAYALAM
Q5→ WAP to input a sentence and print all special words from the sentence. Special words are those words which
starts and ends with the same letter. Eg: window, Existence, comic.
Q6→ Write a program to input a sentence and print the number of characters found in the longest word of the given
sentence.
For example is S = “India is my country” then the output should be 7.
Q7→ WAP to input a sentence and count the words ‘this’, ‘an’, ‘the’ separately.
Q8→ Write a program to enter a sentence from the keyboard and count the number of times a particular word occurs
in it. Display the frequency of the search word.
Eg: INPUT: Enter a sentence : the quick brown fox jumps over the lazy dog.
Enter a word to be searched : the
OUTPUT: Searched word occurs : 2 times.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→123
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String programs - based on words.

Q4→ WAP to input a sentence and print all palindrome words.


124
Input: MOM AND DAD ARE LEARNING MALAYALAM
Output: MOM DAD MALAYALAM

A4→ import java.util.Scanner; for( i = 0; i < len; i++)


public class GetWords {
{ chr = str.charAt(i);
public static void main() if(chr != ' ')
{ { //hello java program
Scanner sc = new Scanner (System.in); wrd = wrd + chr;
String str, wrd = “”, rwrd = “”; rwrd = chr + rwrd;
int i, len; char chr; }
System.out.println("Enter a String "); else
str = sc.nextLine(); {
str = str + " "; if( wrd.equals(rwrd) )
len = str.length(); System.out.println(wrd+ “ ”);
wrd = ""; rwrd = “”;
}
}
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→124
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String programs - based on words.

Q9→ Consider the following statement:


125 “January 26 is celebrated as the Republic Day of India”. Write a program to change 26 to 15, January to August,
Republic to Independence and finally print “August 15 is celebrated as the Independence Day of India”.
Q10→ WAP to input a sentence and print max and min word.
Q11→ Write a program to input a sentence and print the smallest word of the given sentence.
For example: if s = “India is my country” then the output should be ‘is’.

A9→ import java.util.Scanner; for( i = 0; i < len; i++)


public class GetWords { chr = str.charAt( i );
{ if( chr != ' ‘ )
public static void main() wrd = wrd + chr;
else
{
{ if( wrd.equals(“26”) )
Scanner sc = new Scanner (System.in); nstr = nstr + “15”;
String str, wrd = “”, nstr = “”; else if( wrd.equals(“January”) )
int i, len, char chr; ; nstr = nstr + “August”;
System.out.println("Enter a String "); else if( wrd.equals(“Republic”) )
str = sc.nextLine(); nstr = nstr + “Independence”;
str = str + " "; else
nstr = nstr + wrd;
len = str.length();
wrd = "";
}
}
System.out.println(“statement =” + nstr);
} }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→125
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

Q & A - based on words.

126
Q7→ WAP to input a sentence and count the words ‘this’, ‘an’, ‘the’ separately.

A7→ import java.util.Scanner; for( i = 0; i < len; i++)


public class GetWords {
{ chr = str.charAt(i);
public static void main() if(chr != ' ') //hello java program
{ wrd = wrd + chr;
Scanner sc = new Scanner (System.in); else
String str, wrd = “”; {
char chr; if( wrd.equals(“this”))
int i, len, cnt1=0, cnt2=0, cnt3=0; cnt1++;
System.out.println("Enter a String "); else if( wrd.equals(“an”))
str = sc.nextLine(); cnt2++;
str = str + " "; else if( wrd.equals(“the”))
len = str.length(); cnt3++;
wrd = "";
}}
System.out.println(“this” + cnt1 + “an” + cnt2 + ”the”+ cnt3);
}
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→126


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

Q & A - based on words.

127 Q9→WAP to input a sentence and print max and min word.

A9→ import java.util.Scanner;


public class MaxMinWords
maxw = minw = str.substring(0, str.indexOf(‘ ’));
{
for( i = 0; i < len; i++)
public static void main()
{
{
chr = str.charAt(i);
Scanner sc = new Scanner (System.in);
if(chr != ' ') //hello java program
String str, wrd = “”, maxw=“”, minw=“”;
wrd = wrd + chr;
int i, len; char chr;
else
System.out.println("Enter a String ");
{
str = sc.nextLine();
if( wrd.compareTo(maxw)>0)
str = str + " ";
maxw = wrd;
len = str.length();
if( wrd.compareTo(maxw)<0)
minw = wrd;
}
wrd = ""; rwrd = “”;
}
System.out.println(“max:”+maxw+“\n min:”+min);
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→127
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String Theory

128 Differences & Similarity between String & StringBuffer.

String StringBuffer

Once a String object is created you cannot change the StringBuffer objects can be altered on the same instance
characters that comprise the string. after creation.
String objects are immutable. StringBuffer objects are mutable.

New object is required to alter the string. New object is not required.

Similarity: Both the classes are found in java.lang package & are used for string manipulation.

Library classes:
The java environment provides several built-in class libraries that contains many in-built methods for input-output, string
handling etc. This library is also known as Application Programming Interface (API). E.g: Math class, String class,
BufferedReader Class etc.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→128


Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

String output Questions

Q1: Find the output of the following expressions. Outputs


129
a) String st = “YP COMPUTER”;
System.out.println(st.indexOf(st.charAt(6)));
System.out.println("TRANSPARENT".compareTo("TRANSITION"));
b) String s = “application”;
int p = s.indexOf(“a”);
System.out.println(p);
System.out.println(p + s);
System.out.println("ACHIEVEMENT".replace('E', 'A'));
Q2: State the output when the following program segment is executed:
String a = “Smartphone”, b= “Graphic Art”
String h = a.substring(2, 5);
String k = b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
System.out.println (c.indexOf(‘a’, 2));
System.out.println (c.indexOf(‘a’, 3));
Q3: Write the output for the following:
char ch = '2’; int m = ch; m = m + 5;
System.out.println(m + " " + ch);
String s = "Today is Test" ;
System.out.println(s.substring(0, 7) + " " +"Holiday");
System.out.println(“MISSISSIPPI”.indexOf('S')+“MISSISSIPPI”.lastIndexOf(‘I’));
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→129
Ch 4 : String Handling Sub: Computer Application
JMD HGGM
ICSE Class 10th

130

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→130


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

131 Ch_no. Topics Page No.

5. User Defined Functions

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→131


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Methods / Functions
132

Methods/Functions are subprograms or small block of code which perform specific action. Or
A large program can be divided into smaller subprograms. These subprograms are called as function.

Advantages of function:-
➢ Complexity of program is reduced.
➢ Debugging (error checking) can be done easily.
➢ Memory is saved. As only a single copy of the function is
present in the memory but it can be called many times in a
program.

Types Of Function/Method → There are two types of function.


1. In-built / Library function / Pre-defined function
2. User defined function

In-built / Library / Pre-defined Functions


Function / Method

User defined functions

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→132


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

User Defined Function / Method

Functions/Methods which are defined by user is known Four Ways To Declare A Function
133
as User define function/method. 1. int sum ( int, int ); //with argument & with return type
2. void sum ( int, int ); //with argument & without return type
User defined function consists of three parts. 3. void sum ( ); //without argument & without return type
1. Function declaration/Prototype 4. int sum ( ); // without argument & with return type
2. Function calling/invoking
3. Function definition Function calling
Function Calling is used for its execution.
Function Declaration / Prototype Syntax: variable = Function_name(Argument value/variable);
It tells the compiler that a function is defined somewhere
in the program. DECLARATION PARTS CALLING PARTS
Function declaration is not required in java. int sum ( int, int ); s = sum(4, 7); or s = sum(a, b);
void sum ( int, int ); sum(4,7); or sum(a, b);
Syntax void sum ( ); sum( ); or sum();
Return-type function_name (datatype of arguments) int sum ( ); s = sum( ); or s = sum( );

Argument is the information or data, supplied to the


function at a time of calling.

Return type is the data-type of value, returned by


function to the caller part.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→133


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

User Defined Function / Method

Function Definition
134
It defines the purpose of function. Q1 → WAP to input 2 numbers and calculate their sum using function.
Syntax: Formal Parameters
Ans→ public class add
Return-type Function ( Argument var)
{
{
body of Function; static int sum ( int a, int b ) // function definition
} {
int s;
Example: s = a + b;
int sum (int a, int b) return s;
{
int s;
}
s = a + b; public static void main()
Actual Parameters
return s; {
} int a=10, b=20, s;
s = sum(a, b); // function calling
Note: → Return statement is used to return a System.out.println("addition =" + s);
value to the calling part. }
→ A function can return only one value. }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→134


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Questions & Answers

Q2 → WAP to input 3 numbers and calculate their average and product using function.
135

import java.util.Scanner;
Ans→ public class Pro_Avg
{
static int product ( int a, int b, int c ) public static void main()
{ {
int pro; int a, b, c, pro;
pro = a * b * c ; double av;
return pro; Scanner sc = new Scanner (System.in);
} System.out.println("Enter three numbers: ");
static double average ( int x, int y, int z ) a = sc.nextInt();
{ b = sc.nextInt();
double avg; c = sc.nextInt();
avg = (x + y + z)/3.0; pro = product(a, b, c);
return avg; av = average(a, b, c);
} System.out.println(“Product = " + pro);
System.out.println(“Average = " + av);
//another way to call function
System.out.println(“Product = ” + product(a, b, c));
}
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→135
Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Questions & Answers

136
Q3→ WAP to input three numbers and find greatest number using function. (HW)
Q4→ WAP to input a number and print its factors.
Q5→ WAP to input a number and find factorial using function.
Q6→ WAP to input a number and its power and calculate it. (HW)

Ans4→ public class Factors Ans5→ public class FactorialNo


{ {
static void factor ( int n ) static int factorial ( int n )
{ {
System.out.println(“ factors =“ ); int fact = 1;
for( int i = 1; i<=n; i++ ) for( int i = 1; i <= n; i++ )
{ {
if( n%i == 0) fact = fact * i ;
System.out.println( i + “ ”); }
} return fact;
} }
public static void main() public static void main()
{ { int a = 4, f;
int a=20; f = factorial(a);
factor(a); System.out.println(“factorial = " + f);
} }
} }
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→136
Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Questions & Answers

Q7→ WAP to print following menu and


137
solve menu task using functions. void fibonacci( int n ) void arms(int n)
1. Factorial { {
2. Fibonacci series int a = 0, b = 1, c, i; long dig, cube, copy = n, sum=0;
3. Reverse number if( n == 1) while(n>0)
4. Armstrong number System.out.print( a +“ ”); {
5. Prime number else dig = n%10;
6. Exit { cube = dig*dig*dig; //Math.pow(dig,3)
Enter your choice → System.out.print(a+“ ”+b); sum = sum + cube;
for(i = 3; i <= n ; i++) n = n/10;
{ }
Ans7→ public class Factors
c = a+b; if(copy == sum)
{
System.out.print( c +“ ”); System.out.print(“It is Armstrong no.“);
int factorial( int n )
a = b; else
{
b = c; System.out.print(“It is not Armstrong no.“);
int i, f = 1;
} }
for( i = n; i >= 1; i-- )
}
f = f * i;
}
return f;
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→137


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Questions & Answers


void prime(int n) int reverse (int n) System.out.println(“Enter a number “);
{ { n = sc.nextInt();
138
int i, flag = 1; int rev = 0, dig, a; switch(ch)
if(n == 1) {
while( n>0 )
case 1:
System.out.println("not a prime no.“); {
result=factorial(n);
else if(n == 2) dig = n%10; Sop("factorial of “ + n + “ is “ + result);
System.out.print("prime no“); rev = (rev*10) + dig; break;
else n = n/10; case 2:
{ } fibonacci(n);
for(i = n-1 ; i >= 2; i--) return rev; break;
{ } case 3:
if(n%i == 0) { public static void main() result = reverse(n);
flag = 0; { Sop(“reverse number = ” + result);
break; int n, result, ch; break;
} do case 4:
{ arms(n);
}
System.out.println("1. Factorial“); break;
if(flag == 1)
System.out.println("2. Fibonocci series“); case 5:
System.out.print("prime no.“); System.out.println("3. Reverse number“); prime(n);
else System.out.println("4. Armstrong number“); break;
System.out.print("not prime no.“); System.out.println("5. Prime number“); case 6:
} } System.out.println("6.Exit“); System.exit(0);
System.out.println(“Enter your choice →“); }
ch = sc.nextInt(); } while(ch != 6);
Practice Makes Perfect WWW.YPComputerClasses.in
} } 7798161873 p→138
Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Java Functions Theory Points

Function & syntax of declaring a function Prototype of a function check which receives a
139
A function is a sub-program in a main program which processes data & character & an integer argument, returns true or
returns a value. Functions are set of instructions given to a computer to false.
perform some task. public boolean check (char c, int n);
General Syntax:
Function signature
Access-specifier modifier return-type method-name(formal parameters)
Function signature is the parameter list of the
{
function i.e number & type of parameters.
//function body
Eg. public void print( int a, int b);
}

Need of declaring a function Role of keyword ‘void’ in function:


1. Functions make the program modular. When function is declared using keyword void, it
2. They help in code reusability & better memory management. cannot return a value to the calling function.
3. They reduce code redundancy. Such functions cannot be used in an assignment
4. They help to code with complexity of the program & makes error statement.
detection easier.
Invoking of static functions:
Function Prototype Static functions can be invoked without creating
Function prototype is the first line of the function which omits the an object; by classname & dot operator.
function body but does specify the Return-type, method name & Eg. Math.sqrt(25); → where Math is the class
parameter list of the function. name & sqrt is the static function of Math class.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→139


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Java Functions Theory Points

Function overloading Use of return statement:


140
In one class two or more functions with same name but The return statement terminates the function & transfers the
different parameter list i.e. number or type or order of control back to the method call with a value. Once the return
parameters should be different. It implements statement is found the statements after it are skipped. One
polymorphism. function can return only one value. If there are several return
statements only the first one is executed.
Need of function overloading:
It improves the readability of the program & makes the Name the following Keywords:
language extensible. It helps to refer related functions 1. The keyword that causes control to transfer back to the method call.
with same name.
2. The keyword that differentiates class and instance variable.
Example of function overloading
class addition 3. Default value of a string variable.
{ public void add(int a, int b) 4. To create an object.
{
System.out.println(a+b); 5. To create a package.
} 6. For immediate termination of a loop.
public void add(double a, double b)
{ 7. Forces iteration of a loop.
System.out.println(a+b); 8. To define a class function.
}
} 9. To refer the current object.
10. To indicate that the current method does not return an object.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→140
Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Name the following Keywords:


141
11. To keep the value held in a variable unchangeable.
12. Access specifier associated with inheritance.
13. To import the packages that you require in your applications
14. Datatype that has only 2 possible values
15. This has a similar function as that of the else.
16. Used when the loop has predetermined no. of iterations.
17. Access specifier used to make the member available only to the members of the class.
18. Used to define the blueprint or prototype of instances.
19. To define variables which store Unicode values.
20. Alternative for large series of if..else..if construct.
21. This is a exception handling block.
22. Used to create a subclass.
23. Used to force an exception.

Ans→ 1. return 2. static 3. null 4. new 5. package 6. break 7. continue 8. static 9. this 10. void 11. final 12. protected 13. import
14. boolean 15. Default 16. for 17. private 18. class 19. char 20. switch 21. try catch 22. extends 23. throws / throw
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→141
Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Java Functions Theory Points

Early binding/Static binding


142
When the function call in a program is decided during the compilation it is known as early binding or static binding.

Late binding/Dynamic binding


When the function call in a program is decided during the execution of the program it is known as late binding or dynamic
binding.

Use of ‘this’ keyword


The ‘this’ keyword is used as reference to the current object i.e. on which the function is invoked. It is an inbuilt object for
each class. It is used to resolve name conflict between local variable & instance variable.
E.g. class box
{
int a, b; //Instance variable
public box(int a, int b) //local variable
{
this.a = a;
this.b = b;
}
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→142


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Difference between Instance variable & Class variable.

143 Instance Variable(Non-static) Class variable(Static variable)


They are declared without the static keyword. They are declared with the static keyword.
Every object has its own copy of instance variable. All the objects share a single copy of class variable.
The lifetime of instance variable depends upon an object. The lifetime of class variable depends upon a class.
Instance variables can be accessed only by an object. Class variable can be accessed without an object.
Eg. Objectname.var, Objectname.functionname(); Eg. Classname.var

Difference between Actual parameter & Formal parameter.

Actual Parameter/Argument Formal Parameter/Argument


The parameters passed in the function call statement are The parameters passed in the function prototype are
Actual Parameters. Formal Parameters.
They are not preceded by data type. They are preceded by data type.
It is also known as Arguments. It is also known as dummy parameters.
Eg. obj.print(x, y); Eg. public void print(int a, int b);

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→143


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Two ways to invoke a function

1. Call by Value. 2. Call by Reference


144
Difference between call by value and call by reference
Call by Value Call by Reference

The value of actual parameters is copied in to formal The Reference of actual parameters is copied in to formal
parameters. parameters.

Any changes made to formal parameters do not affect Any changes made to formal parameters affects the
actual parameters. actual parameters.

Actual parameters passed are of primitive types. Actual parameters passed are of non-primitive type.

Eg. static void prod1(int a, int b) public void main() Eg. static void prod2(int c[ ]) public void main()
{ { { {
a = a*2; int a=10, b=20; c[0] = c[0] * 2; int c[ ] = {10, 20};
b = b*3; prod(a, b); c[1] = c[1] * 3; prod(c);
} Sop(“A=“+a); } Sop(“c[0]=“ + c[0]);
Sop(“B=“+b); Sop(“c[1]=“ + c[1]); }
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→144


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

Method output Questions

Q.1: Q2:
145
a) Define: Function prototype line. a) Write the main function to invoke the following functions:
b) Debug the error and rewrite the following function prototype: i. Class Test {
(1) float product(a, int y); (2) float operator (int x, float = 3.4); public int mult(int x, int y)
c) If Car is a class, write a statement to create an object BMW. { return x*y; }
d) Give the output of the following code: }
void add(int a, int b) ii. Class Demo {
{ System.out.println( a + b ); } public void add(int x, int y)
void add(String a,String b) { System.out.println((x+y)); }
{ System.out.println( a + b ); } }
iii. Class Example{
If (i) add(“12”, “4”) is invoked. static int a=100, b=200;
(ii) add(4, 12 ) is invoked. public static void print()
e) { System.out.println(a+b);
(1) Name the function which does not change or modify the state of }
the arguments / variable that are received when called. }
(2) Name the statement/function that causes the control to transfer
back to method call. b) write a function prototype of the following:
f) What are the two ways of invoking functions? A function PosChar which takes a string argument and
g) What are the two types of functions? (pure, impure) a character argument and returns an integer value.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→145


Ch 5 : User-defined Methods Sub: Computer Application
JMD HGGM
ICSE Class 10th

146

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→146


Index Page Sub: Computer Application
JMD HGGM
ICSE Class 10th

Contents

147 Ch_no. Topics Page No.

6. Class and Object Programming


7. Constructor
8. Encapsulation

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→147


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Oop In Java

Procedural Oriented Programming (POP)


148 Procedural programming paradigm focuses on breaking down a programming task into a collection of small modules known
as sub routines or procedures / function. It follows top down approach in program design. It uses procedures to operate on
data. It doesn’t have any access specifier. In POP, Overloading is not possible. It doesn’t provide Data Hiding so provides
less security. Examples are ALGOL, COBOL, BASIC, PASCAL, C etc.

Object Oriented Programming (OOP)


It is a very user friendly and a powerful approach to solve basic to difficult problems. It bundles data and methods together
in a single unit which is known as data Encapsulation. It follows bottom up approach in program design. It has access
specifiers named Public, Private, Protected, etc. Object Oriented Programming allows some special features such as
Polymorphism, Inheritance and Data hiding. In OOP, Overloading is possible in the form of function overloading and
Operator overloading. It provides Data Hiding so provides more security. The three most common examples are Smalltalk,
C++ and Java.
Features Of Oop :
1. Class. 2. Object. 3. Data Hiding. 4. Data Encapsulation & Abstraction.
5. Inheritance. 6. Polymorphism.

Data Encapsulation
Wrapping up of data members and member methods together in a single unit which is known as Data Encapsulation.
Abstraction:
Abstraction is the act of representing essential features without getting in to complexity of the system.
Eg: We know how to drive a car. But we don’t know the mechanism that makes the car move.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→148
Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Components of OOP

The major components of Object Oriented Programming are as follows:


149 1. Class 2. Object 3. Data Members & Methods 4. Access Specifier and Visibility Modes

CLASS
Class is a user defined data type in which data members and member functions/methods are combined together in a single
unit. It is also known as Data Encapsulation.
Class ➔ Data Members + Member Functions / Methods
Class helps to keep the data members in various visibility modes as private, public and protected. Usually, data members of
a class are kept in private or protected visibility modes and methods are kept in the public visibility mode. In java, Default
access specifier is public.

Private members are available to only own class and not accessible to function outside the class.
Private member data & function cannot be accessed outside the class. It is known as Data Hiding. They can be accessed
only through public members of the class.
Public members are the members which accessible from anywhere either inside or outside.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→149


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Creating Class & Object

How To Create A Class :


150
Syntax:
public class class_name
{
private Data members declaration;
public Member functions declaration;
}
OBJECT :
Object is an instance (variable) of a class that is capable of holding actual data in memory locations. All objects of the same
class have same properties & functions. Objects can access only public members of the class.
Class and objects are related to each other in the same way as data type and variables.
Syntax To Create an Object
Class_name Object_name1 = new Class_name();
Eg: Student s1 = new Student();

NEW: It is a keyword which is use to create an object and helps to allocate memory to an object.
Object can access the public member data & function of class using dot(.) operater.
How To Access : Example:
Syntax: S1.input();
ObjectName . publicMemberName; S1.x;

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→150


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

OOP Program Using BufferedReader class

Q1→ Create a class named as Student which having public void calc()
151
Data members → name, rollno, marks of 3 subs, total, perc, {
Member functions → void input(), void calc(), void display(). tot = m1 + m2 + m3;
(Using BufferedReader class) perc = tot/3.0;
}
A1→ import java.io; void display()
public class Student {
{ System.out.println("rollno="+rollno);
private int rollno, m1, m2, m3, tot; System.out.println("name="+n);
private String n; System.out.println("marks="+m);
private double perc; }
public void input() public static void main() throws IOException
{ {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Student s1 =new Student(); //s1 is object.
System.out.println("Enter name, rollno, marks of 3 subs"); Student s2 =new Student(); //s2 is object.
n = br.readLine(); s1.input(); // calling of the function
rollno = Integer.parseInt(br.readLine()); s2.input();
m1 = Integer.parseInt(br.readLine()); s1.calc(); s2.calc();
m2 = Integer.parseInt(br.readLine()); s1.display(); s2.display();
m3 = Integer.parseInt(br.readLine()); }
} }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→151


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

OOP Program Using Scanner class

Q1→ Create a class named as Student which having public void calc()
152
Data member → name, rollno, marks of 3 subs, total, perc. {
Member function → void input(), void calc(), void display(). tot = m1 + m2 + m3;
(Using Scanner class) perc = tot/3.0;
}
A1→ import java.util.Scanner; void display()
public class Student {
{ System.out.println("rollno="+rollno);
private int rollno, m1, m2, m3, tot; System.out.println("name="+n);
private String n; System.out.println("marks="+m);
private double perc; }
public void input() public static void main()
{ {
Scanner sc = new Scanner( System.in ); Student s1 =new Student(); //s1 is object.
System.out.println("Enter name, rollno, marks of 3 subs"); Student s2 =new Student(); //s2 is object.
n = sc.nextLine(); s1.input(); //calling of the function
rollno = sc.nextInt(); s2.input();
m1 = sc.nextInt(); s1.calc(); s2.calc();
m2 = sc.nextInt(); s1.display(); s2.display();
m3 = sc.nextInt(); }
} }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→152


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Questions

Q2→ Create a class named as Distance which having


153
Data members → feet, inches.
Member functions → void input(), void calc(), void display(). Hint - 1 feet = 12 inches;
Q3→ Create a class named as employee which having
Data members → empname, basicSalary, TA, DA, HRA, TotalSalary.
Member functions →
void input() → Input empname and basic salary.
void calc() → Calculate TA(travelling Allowance) = 35%of BS, DA(Dearness Allowance) = 35%of BS, HRA(House
Rent Allowance) = 25% of BS, Total Salary(TS) = BS + TA + DA + HRA;
void display()→ display all details
Q4→ Create a class named as Stock which having data member → itemname, quantity, price, amount
member function → void input(), void input(String, int, int), void calc(), void display().
Here overloaded function is input.

Overloading of Function:
Function with same name but differ in their number of arguments or datatype of arguments is called as overloading
of function.
Eg: void input( );
void input( int );
void input( int, int );
void input( int, double );
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→153
Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Passing Argument/parameter in a Function or Function Overloading.


Q2→ Create a class named as Distance which having Data Members → feet, inches.
154
Member Functions → vod input(), void calc(), void display().

import java.io.*; public void calc()


public class Distance {
{ int feet,inch; while( inch>=12 )
public void input() {
{ inch=inch -12;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
feet++;
System.out.println("Enter feet and inches"); }
feet = Integer.parseInt(br.readLine()); }
inch = Integer.parseInt(br.readLine()); public static void main( ) throws IOException
} {
public void input(int f, int i) Distance d1 = new Distance(); //s1 is object
{ Distance d2 = new Distance(); //s2 is object
feet = f ; d1.input(); //calling of the function
Formal parameters
inch = i ; d2.input(5, 9);
} d1.calc();
public void display1() d2.calc(); Actual parameters
{ d1.display1();
System.out.println(“ feet & inches = “ + feet + "\' “ + inch + "\” "); d2.display1();
} }
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→154
Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Passing Argument/parameter in a Function or Function Overloading.


Q2→ Create a class named as Distance which having Data Members → feet, inches.
155
Member Functions → vod input(), void calc(), void display(). (Using Scanner)

import java.util.*; public void calc()


public class Distance {
{ int feet, inch; while( inch>=12 )
public void input() { //How to do this calculation
{ inch=inch -12; without loop
Scanner sc = new Scanner(System.in); feet++;
System.out.println("Enter feet and inches"); }
feet = sc.nextInt(); }
inch = sc.nextInt(); public static void main( )
} {
public void input(int f, int i) Distance d1 = new Distance(); //s1 is object
{ Distance d2 = new Distance(); //s2 is object
feet = f ; Formal parameters d1.input(); //calling of the function
inch = i ; d2.input(5, 9);
} d1.calc();
public void display1() d2.calc(); Actual parameters
{ d1.display1();
System.out.println(“ feet & inches = “ + feet + "\' “ + inch + "\” "); d2.display1();
} }
}
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→155
Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Array of Object :

156
Q5→ Create a class named as Tel_dir to store
name, address, telephoneno.
Store and print data of 5 persons.
class tel_dir
{
String name, addr, tel;
void input() { }
void display() { }
public static void main( String arg[] )
{
tel_dir t [ ] = new tel_dir[5] ;
for ( int i = 0; i < = 4 ; i++ )
{
t[ i ] = new tel_dir();
t[ i ].input ( );
}
for ( i = 0 ; i < = 4 ; i++)
t[ i ].display ( );
}
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→156


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Class & Objects Related Questions

Q6→ Design a class RailwayTicket with following description:


157
Instance variables/data members :
String name : To store the name of the customer
String coach : To store the type of coach customer wants to travel
long mobno : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalamt : To store the amount to be paid after updating the original amount
Member methods :
void accept () – To take input for name, coach, mobile number and amount.
void update() – To update the amount as per the coach selected
(extra amount to be added in the amount as follows)
Type of Coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
sleeper None

void display() – To display all details of a customer such as name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→157


Ch 6 : Class as the Basis of all Computation (Classes & Objects) Sub: Computer Application
JMD HGGM

Class & Objects Related Questions

Q7→ Define a class ElectricBill with the following specifications:


158
class : ElectricBill
Instance variables / data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to be paid
Member methods:
ElectricBill(String name, int un) - create a parameterized constructor to initialize name and units only.
void accept( ) – to accept the name of the customer and number of units consumed
void calculate( ) – to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print ( ) - To print the details as follows:
Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………
Write a main method to create an object of the class and call the above member methods.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→158


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Constructors
Constructor
159 It is a special member function that is used to initialize the object of the class.
➢ Constructor name should be same as class name.
➢ Constructor does not have any return type (not even void).
➢ Constructor is called automatically when the object is created.
➢ Constructor can be overloaded.( It means more than one constructor can be provided in the class.)

There are three types of constructor


1. Default constructor
2. Parameterized / regular constructor
3. copy constructor

Default constructor : Constructor without argument is called as default constructor.

Parameterized constructor : Constructor with argument is called as parameterized constructor.


Constructor overloading
When we create more than one constructor in a class then this concept is called constructor Overloading.
Copy constructor
A copy constructor is a special constructor in the C++ programming language for creating a new object as a copy of an
existing object.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→159


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Example of default, parameterized, copy, overloading constructor.

Q8→ public void calc()


Create a class named as Distance which //Default Constructor Note:
160
public Distance( ) { while(inch>=12) Every class has
having Data members → feet, inches. {
Member functions → void input(), { an implicit
feet = 0; inch=inch-12; constructor
void calc(), feet++;
void display(). inch = 5; which need not
} } to be defined.
(Hint: 1 feet=12 inches) }
// Parameterized Cons. public void display()
import java.util.*; {
public class Distance public Distance( int f, int i)
{ System.out.println(feet+" \' "+inch+" \" ");
{ }
private int feet,inch; feet = f ;
inch = i ; public static void main( )
} {
public void input() Distance d1 =new Distance();
{ Distance d2 =new Distance( 5, 7);
Scanner sc = new Scanner(System.in)); //Copy Cons.
public Distance(Distance dst) Distance d3 =new Distance( d1);
System.out.println("Enter feet & inches"); d1.calc();
feet = sc.nextInt(); {
feet = dst.feet ; d2.calc();
inch = sc.nextInt(); d1.display();
} inch = dst.inch ;
} d2.display();
d3.display(); } }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→160


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Constructor Programs

Q9: Q10:
161 Define a class named BookFair with the following description: Design a class name ShowRoom with the following description :
Instance variables/Data members : Instance variables/ Data members :
String Bname — stores the name of the book String name – To store the name of the customer
double price — stores the price of the book Member methods : long mobno – To store the mobile number of the customer
(i) BookFair() — Default constructor to initialize data members double cost – To store the cost of the items purchased
(ii) void Input() —To input and store the name and the price of the double dis – To store the discount amount
book. double amount – To store the amount to be paid after discount
Member methods: –
(iii) void calculate() — To calculate the price after discount.
ShowRoom() – default constructor to initialize data members
Discount is calculated based on the following criteria.
void input() – To input customer name, mobile number, cost
void calculate() – To calculate discount on the cost of purchased
Price Discount items, based on following criteria
Less than or equal to Rs. 1000 2% of price
Cost Discount
More than Rs. 1000 and less 10% of price
Less than or equal to Rs. 10000 5%
than or equal to Rs. 3000
More than Rs. 10000 and less than or equal to Rs. 20000 10%
More than % 3000 15% of price
More than Rs. 20000 and less than or equal to Rs. 35000 15%
(iv) void display() — To display the name and price of the book More than Rs. 35000 20%
after discount.
Write a main method to create an object of the class and call the void display() – To display customer name, mobile number, amount to
above member methods. be paid after discount
Write a main method to create an object of the class and call the
above member methods.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→161
Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Constructors Program Q10 Solution

import java.io.*; void calculate( ) void display( )


162 import java.util.*; { {
class ShowRoom if (cost <= 10000) System.out.println(“Name::” +name);
{ { System.out.println(“Mobile No.::” +mobno);
String name; dis = cost*5/100; System.out.println(“Amount::” +amount);
long mobno; amount = cost – dis; }
double cost, dis, amount; } public static void main(String args( ))
ShowRoom( )
else if(cost>10000 && cost<=20000) {
{
{ ShowRoom ob = new ShowRoom( );
name = “ ”;
dis = cost* 10/100; ob.input( );
mobno =0;
cost = 0;
amount = cost – dis; ob.calculate( );
dis = 0; } ob.display( );
amount = 0; else if(cost>20000 && cost<=35000) }
} { }
void input( ) dis = cost* 15/100;
{ amount = cost – dis;
Scanner sc = new Scanner(System.in); }
System.out.println(“EnterName:”); else if (cost > 35000)
name = sc.nextLine( ); {
System.out.println(“Enter Mobile number:”); dis = cost*20/100;
mobno = sc.nextLong( ); amount = cost – dis;
System.out.println(“Enter cost:”); }
cost = sc.nextDouble( ); }
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→162


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Passing Object in Function as an Argument:

Q11→ Add the d1 object and d2 object and store in d3 public static void main(String ar[ ])
163
object of distance class. {
distance d1 = new distance();
class distance distance d2 = new distance();
{ distance d3 = new distance();
private int feet, inch; sop(”Enter data in first object”);
public void input() d1.input();
{ sop(”Enter data in second object”);
do it yourself d2.input();
} d3.add(d1, d2);
sop(”After adding d1 & d2 object, newly object is“);
public void add(distance fd1, distance fd2) d3.display();
{ }
feet = fd1.feet + fd2.feet; }
inch = fd1.inch + fd2.inch;
}
public void display()
{ do it yourself }

Note: Data of the objects which are passed as an argument in function is used through the object name with dot(.) operator.
Eg: fd1.feet → Data of the object which is calling the function can be used directly.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→163


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Returning Object from Function:

Q12→ Add the d1 object and d2 object and store in d3 public static void main(String ar[ ])
164
object of distance class. {
A→ class distance distance d1 = new distance();
{ distance d2 = new distance();
private int feet, inch; distance d3 = new distance();
public void input() sop(”Enter data in first object”);
{ do it yourself } d1.input();
sop(”Enter data in second object”);
public distance add(distance fd2) d2.input();
{ d3 = d1.add(d2);
distance temp; sop(”After adding d1 & d2 object, newly object is“);
temp.feet = feet + fd2.feet; d3.display();
temp.inch = inch + fd2.inch; }
return temp; }
}
public void display()
{ do it yourself }
Q13→ Add two time objects without returning object.
Data member – hours, minutes, seconds
Member functions – void input(), void calc(), void display().
Q14→ Add two time object with returning object.
Q15→ Add two string object and store it in third string object

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→164


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Static Keyword & static method


Static Keyword Q16→ Create a class called as library and Data
165 members are Id , name, price. And create functions
Static variable / static class data:
for unique id for each book , display total no. of book,
➢ It declared with static keyword.
void input() and void display().
➢ A single copy of static data member is created. All object of
class can share the static data. import java.io.*;
➢ It is not stored in object. It is stored separately as a part of class Library
class. {
➢ It is automatically initialized by 0. private int id;
private static int count;
Static member function: private String n;
➢ It is declared with static keyword. private double p;
public Library()
➢ It can access only static data of class.
{
➢ It is called through class name (Not by object). count++;
id = count;
}
void input()
{
Scanner sc = new Scanner(System.in));
System.out.println("Enter name and price");
n = sc.nextInt();
p = sc.nextDouble();
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→165


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

public void display()


this → ‘this’ keyword is used to point out the current object by
{
166 which a method is called.
System.out.println(id + “\t” + n + “\t” + p);
}
Eg: class abc
public static void tot_num()
{
{
int x, y;
System.out.println(“total no. of books =” + count);
abc(int x, int y)
}
{
public static void main(String[] args)
this.x = x;
{
this.y = y;
Libray li[] = new Library[3];
}
for(int i=0; i<=2; i++)
void show()
{
{
li[i] = new Library();
System.out.print(x + “ ”+ y);
li[i].input();
}
}
public static void main(String ar[])
System.out.println("id \t books name \t books price\n");
{
for(int i=0; i<=2; i++)
abc ob = new abc(1,3);
{ sd[i] = new Library();
ob.show();
sd[i].display();
}
}
}
tot_num();
} }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→166


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Inheritance

Inheritance Types of Inheritance


167 Inheritance is a process of creating new class from the 1. Single Inheritance 3. Hierarchical Inheritance
existing class. The existing class is called as super class or
base class or parent class. The newly created class is called S S
as derived class or sub class or child class. Inheritance is the
most powerful feature of Object Oriented Programming. The
process of Inheritance does not affect the base class. D
D1 D2 D3
Super class

2. Multilevel Inheritance 4. Multiple Inheritance


Sub class
S S1 S2
➢ Derived class inherits the features of base class.
➢ Derived class has its own features also.

Advantages of Inheritance D1 D
➢ Reusability of code:
➢ Reusability of code saves money as well as time and Note: Java does not support
increases program reliability. D2 multiple inheritance
➢ Protection is never decreased while deriving the class.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→167


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Inheritance

5. Hybrid inheritance
168
S

D1 D2

D3

Access Specifiers
There are three types of access specifiers.
1) Private
2) Public
3) Protected

Creation of Derived class : Syntax:

Class DerivedClassName extends BaseClass


{
Data member;
+
Member function;
}
Note : Object is created only of derived class.
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→168
Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Inheritance program

Q18→ WAP To create a Single Inheritance. Super class is manager (data member - Mcode, Mname ),
169
Child class is employee (Ecode, Ename ), Functions are void input() and void display().
import java.util.*; class employee extends manager //derived class
class manager //base class {
{ private int ecode;
private int mcode; private String ename;
public void input() throws IOException
private String mname;
{
public void input() throws IOException
super.input();
{ // super.mcode=10; //if it is public
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
System.out.println("Enter manager code and name"); System.out.println("Enter manager code and name");
mcode = sc.nextInt(); ecode = Integer.parseInt(br.readLine());
mname = sc.next(); ename = br.readLine();
} }
public void display() public void display()
{ {
System.out.println("manager code "+mcode); super.display();
System.out.println("manager name "+mname); System.out.println("employee code "+ecode);
System.out.println("employee name "+ename);
}
}
}
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→169


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Inheritance PACKAGE

public class single_inheritance Package:


170
{ It is a collection of classes. It works just like a header file in
public static void main(String[] args) throws IOException c++. It provides code reusability.
{ Syntax:
employee e = new employee(); package package_name;
//super.input(); Code
` e.input(); Eg:
//super.display(); package p1;
e.display(); class abc
} {
} int x;
SUPER keyword: void show()
This keyword is used to call the parent class data member and { System.out.print(“hello”) }
member function. }

How to use a package


import keyword is used to include package in program.
import p1.*;
import p1.asd;

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→170


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Pre defined packages

Java Libraries in JDK


171
Java package is a collection of various classes. Each class contains different functions. A package can be included in the
program by using a keyword ‘import’.
Eg: import java.io.*;
import java.util.Scanner; // importing only Scanner class of util package.
import java.util.* // importing all class of util package.

• java.lang - Default package, it will automatically be imported in any java program to


avail its classes and functions. It contains String/Character, Math, Integer classes etc.
• java.io - for input & output statements
• java.util - for Scanner class and other classes.
Java • java.math - for mathematical functions.
packages • java.applet - Applet specific environment
• java.awt - used for GUI
• java.txt - for dates, times and currency
• java.net - used for network and URL

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→171


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Exception Handling:

Exception handling: Syntax:


172
When error comes at run time then that error is called exception. Run try
time error terminates our program execution. If we want that our {
program run properly in case of exception then we do exception Statements
handling. Or }
Run time errors are also called exceptions, and handling such errors catch(Exception ex)
in the application is called exception handling. {
Statements
Java exception handling is done using five keywords: }
try
catch Exception Classes
throw ArithmeticException
throws ArrayIndexOutOfBoundsException
finally. NullPointerException
InterruptedException
try { }
Statements that can raise an error are placed inside the try { } block.

catch( )
This block is used to catch the exception error raised by try block.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→172


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Exception Handling:

throws:-
173 It is used when a method is throw an exception and there is no
exception handling in a body of function. Exception is catch in
that block where method is called.
Syntax Function_name( ) throws Exception_name
{
Statement;
}
Example3:
public class abc
{
void divide(int a, int b)
{
int c= a/b;
System.out.print(c);
}
public static void main(String[] args) throws Exception
{
abc ob = new abc();
ob.divide(10, 0);
} }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→173


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

OOP Theory Points

Object Oriented Programming


174
In object oriented programming, programs can be divided in to smaller segments & then connected together to make a
whole conceptualized unit.

Process Oriented Object Oriented


The program revolves around the code. The program revolves around the data.
It follows top-to-bottom approach. It follows bottom-to-top approach.

Eg: C, Basic, Fortran Eg: C++, Java

Class: A class is a blueprint or a prototype that defines characteristics & behaviour common to all objects of a certain kind.
It is the fundamental building block of Object Oriented Programming.
Eg: class - Student
characteristics: name, roll, std, marks.
Behaviour: calc_tot(), calc_per().

Object:
Object is an identifiable entity with some characteristics & behavior. It can be a place, a thing or a human.
Eg. Dog have state(name, colour, breed) & behaviour (barking, fetching, wagging the tail).

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→174


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

OOP Theory Points

Objects related to a class: Principles of OOP & their benefits:


175 A class is a blueprint or prototype that defines variables & Encapsulation:
methods common to objects of same kind. It combines objects & Wrapping and bundling of data & functions together
methods for manipulating the data in to one neat package. in to a single unit called class is known as
Differentiate class & objects: Encapsulation. It prevents data from outside use &
interference. Encapsulation is implemented through
Class Objects access-specifiers.
Benefits: Modularity & Information Hiding.
A class is a template for an A object is an instance of a
object. class.
Inheritance: It is an ability of object of one class to
Class does not exist in the Object exist in the computer acquire properties of object of another class. It
computer memory. memory. follows the concept of hierarchy.
Benefits: It helps in code re-usability.
Object factory:
A class is known as object factory as you can create numerous Polymorphism: It means one thing many forms. It
objects of similar characteristics & behaviour from a class. A class is an ability of one object to respond to same
determines the nature of an object. message in one or more different ways.
Class encapsulate: Benefits: Function Overloading & Overriding.
A class encapsulates state & behaviour of an object i.e. data
members & member methods.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→175


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

OOP Theory Points

INHERITANCE
176
Inheritance is a process of creating new class from the existing class. The existing class is called as super class or base
class or parent class. The newly created class is called as derived class or sub class or child class. Inheritance is the most
powerful feature of Object Oriented Programming. The process of Inheritance does not affect the base class.
Base class & Derived class:
Base class is an existing class from which new classes are derived. It is also known as super class or Parent class.
Derived class is a new class which inherits properties from a base class. It is also known as sub class or child class.
Super class

Sub class
➢ Derived class inherits the features of base class.
➢ Derived class has its own features also.

Advantages of Inheritance
➢ Reusability of code:
➢ Reusability of code saves money as well as time and increases program reliability.
➢ Protection is never decreased while deriving the class.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→176


Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

Output Questions

Q1: Classify the following as primitive or non-primitive data Q6: In the program given below, state the name and the value of the (i) to (iv)
177 types: i) Method argument or argument variable
(i) char (ii) arrays (iii) int (iv) classes ii) Class variable
iii) Local variable
Q2: Name the following: iv) Instance variable
(i) Any one reference datatype v) What is object name of class myClass.
vi) Give the type of function used and its name.
Q3: List the variables from those given below that are vii) Name the variables for which each object of the class will have its
composite datatypes. own distinct copy.
(i) Static int x; (ii) boolean b; (iii) arr[i]=10 viii) Name the variables which are common to all objects of the class.
(iv) Private char chr (v) obj.display() (vi) String str
Class myClass
Q4: State the difference between constructor and Method.
{
static int x = 7;
Q5: What is call by value?
int y = 2;
How are the following passed?
public static void main(String args[])
(i) Primitive types
{
(ii) Reference types
myClass obj = new myClass();
System.out.println(x);
void sampleMethod(int n)
obj.sampleMethod(5);
{
int a=6; System.out.println(n);
System.out.println(a); System.out.println(n);
} }
Ans→ Q6 vii) y viii) x } //end of class
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→177
Ch 7 : Constructors (classes & Objects) Sub: Computer Application
JMD HGGM

178

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→178


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

Access specifiers in Java

179
1) Private
➢ Data members and methods declared as private are accessible only in the same class where they are declared.
➢ It is the most restrictive access specifier.

2) Protected
➢ Data members and methods declared as protected are accessible only in the same class where they are declared,
classes of the same package and in its derived classes.
➢ It is associated with inheritance.

3) package/default/friendly
➢ Data members and methods are accessible only in the same class where they are declared and in the classes which
are in the same package.
➢ It is the default access specifier.

4) public:
➢ Data members and methods declared as public are accessible everywhere, ie, same class, different class, same
package, different package as well.
➢ It is the least restrictive access specifier.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→179


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

Types of Variables in Java

180
1) Instance variables
➢ Each object has its copy of instance variables.
➢ If any object changes its instance variable, the change is only reflected in that object.
➢ Accessible in all the functions of the class(non-static functions).

2) Static variables
➢ All objects share a common copy of the static variables.
➢ Changes made by any object in the static variables are reflected in all the objects.
➢ Accessible in all the functions of the class.

3) Local variables
➢ Variables declared within a block (not directly inside a class) are called local variables.
➢ They have their scope limited to the block in which they are declared.

4) Parameter variable
➢ The variables which are taken as formal parameters to any function are parameter variables.
➢ They have their scope limited to the function to which they are passed.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→180


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

PREVIOUS YEAR OUESTIONS

181
Year 2018
Q1) How are private members of a class different from public members?
Ans: The public members can be accessed by any class in any package. The private members allow only the methods of
the same class to access them.

Year 2016
Q2) Name any two types of access specifiers.
Ans: public and private

Year 2015
Q3) The access specifier which gives most accessibility is _____ and which gives least accessibility is_______.
Solution: public, private

Year 2014
Q4) Consider the following class:
public class myClass
{
public static int x=3,y=4;
public int a=2,b=3;
}

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→181


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

PREVIOUS YEAR OUESTIONS

Year 2012
182
Q5) Differentiate between public and private modifiers for members of a class?
Q6) In the program given below, state the name and the value of the
i) method argument or argument variable. ii) class/variable.
iii) local Variable. iv) instance variable.
class myClass
{
static int x = 7;
int y = 2;
public static void main (String args[])
{
myClass obj = new myClass();
System.out.println(x);
obj.sampleMethod(5);
int a = 6;
System.out.println(a);
}
void sampleMethod(int n)
{
System.out.println(n);
System.out.println(y); } }

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→182


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

PREVIOUS YEAR OUESTIONS

Year 2010
183
Q5) Differentiate between private and protected visibility modifiers.
Year 2009
Q6) Consider the following code and answer the questions that follow:
class academic
{
int x, y;
void access()
{
int a, b;
academic student = new academic
System.out.println(“Object created");
}
}
i) What is the object name of class academic?
ii) Name the class variables used in the program?
iii) Write the local variables used in the program.
iv) Give the type of function used and its name.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→183


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

PREVIOUS YEAR OUESTIONS

Year 2006
184
Q7) What is meant by private visibility of a method?
Ans: Data members and methods declared as private are accessible only in the same class where they are declared.
Private methods can be accessible or called in the same class where they are declared. It is the most restrictive

access specifier.
Access Level Access Modifier In same class In Same Package In Sub class Anywhere
Private private Yes No No No
default none Yes Yes No No
protected protected Yes Yes Yes No
Public Public Yes Yes Yes Yes

Difference between local and global variables.


Local variables Global variables
Variable declared within a block (not directly inside a class) Variables declared inside the class block are global
is called a local variable. variables. (instance or static)
They are accessible only in the block in which they are They are accessible throughout the class.
declared.

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→184


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

185

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→185


Ch 8: Encapsulation (classes & Objects) Sub: Computer Application
JMD HGGM

186

Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→186

You might also like