ICSE Supplement - 2 July
ICSE Supplement - 2 July
ICSE Supplement - 2 July
ICSE
COMPUTER
APPLICATIONS
SUPPLEMENT
ps Syllabus
COMPUTER APPLICATIONS
CLASS IX
Effective from the session 2018-19
AIMS:
Ki
1. To empower students by enabling them to build their own applications.
2. To introduce students to some effective tools to enable them to enhance their knowledge, broaden horizons, foster
creativity, improve the quality of work and increase efficiency.
3. To develop logical and analytical thinking so that they can easily solve interactive programs.
4. To help students learn fundamental concepts of computing using object oriented approach in one computer
language.
5. To provide students with a clear idea of ethical issues involved in the field of computing.
CLASS IX
There will be one written paper of two hours duration carrying 100 marks and Internal Assessment of 100 marks.
The paper will be divided into two sections A and B.
Section A (Compulsory - 40 marks) will consist of compulsory short answer questions covering the entire syllabus.
Section B (60 marks) will consist of questions which will require detailed answers. There will be a choice of questions in
the section.
THEORY - 100 Marks
1. Introduction to Object Oriented Programming concepts
(i) Principles of Object Oriented Programming, (Difference between Procedure Oriented and Object oriented).
Computer Applications|Kips 1
(ii) Introduction to JAVA - Types of java programs - Applets and Applications, Java Compilation process, Java Source
code, Byte code, Object code, Java Virtual Machine (JVM), Features of JAVA.
(Definition of Java applets and Java applications with examples, steps involved in compilation process,
definitions of source code, byte code, object code, JVM, features of JAVA - Simple, Robust, secured, object
oriented, platform independent, etc.)
2. Elementary Concept of Objects and Classes
Modelling entities and their behaviour by objects, a class as a specification for objects and as an object factory,
computation as message passing/method calls between objects (many examples should be done to illustrate this).
Objects encapsulate state (attributes) and have behaviour (methods). Class as a user defined data type.
(A class may be regarded as a blueprint to create objects. It may be viewed as a factory that produces similar objects.
A class may also be considered as a new data type created by the user, that has its own functionality.)
3. Values and data types
Character set, ASCII code, Unicode, Escape sequences, Tokens, Constants and Variables, Data types, type
conversions.
Escape sequences [\n, \t, \\, \", \'], Tokens and its types [keywords, identifiers, literals, punctuators, operators].
Primitive types and non-primitive types with examples, introduce the primitive types with size in bits and bytes,
implicit type conversion and Explicit type conversions.
4.
operator.
ps
Operators in Java
Forms of operators, Types of operators, Counters, Accumulators, Hierarchy of operators, 'new' operator, dot (.)
(Forms of operators (Unary, Binary, Ternary), types of operators, (Arithmetic, Relational, Logical, Assignment,
Increment, Decrement, Short hand operators), Discuss precedence and associativity of operators, prefix and postfix,
Creation of dynamic memory by using new operator, invoking members of class using dot operator, Introduce
System.out.println() and System.out.print() - for simple output.)
(Bitwise and shift operators are not included).
Ki
5. Input in Java
Initialization, Parameter, Introduction to packages, Input streams (Scanner Class), types of errors, types of
comments.
(Initialization - Data before execution, Parameters - at the time of execution - using methods of Scanner class
[nextShort(), nextInt(), nextLong(), nextFloat(), nextDouble(), next(), nextLine(), next(),charAt(0)]
Discuss different types of errors occurring during execution and compilation of the program (syntax errors, runtime
errors and logical errors). Single line comment (\\) and multiline comment (/*....*/))
6. Mathematical Library Methods
Introduction to package java.lang [default], methods of Math class.
(pow(x,y), sqrt(x), cbrt(x), ceil(x), floor(x), round(x), abs(a), max(a, b), min(a, b) random().
Java expressions - using all the operators and methods of Math class.)
7. Conditional constructs in Java
Application of if, if else, if else if ladder, switch-case, default, break.
(If, if else, if else if, Nested if, switch case, break statement, fall through condition in switch case, Menu driven
programs, System.exit(0) - to terminate the program.)
2 Computer Applications|Kips
8. Iterative constructs in Java
Definition, Types of looping statements, entry controlled loops [for, while], exit controlled loop [do while], variations
in looping statements, and Jump statements.
Syntax of entry and exit controlled loops, break and continue, Simple programs illustrating all three loops, inter
conversion from for - while - do while, finite and infinite, delay, multiple counter variables (initializations and
updations). Demonstrate break and continue statements with the help of loops.
Loops are fundamental to computation and their need should be shown by examples.
9. Nested for loops
Introduce nested loops through some simple examples. Demonstrate break and continue statements with the
help of nested loops.
(Programs based on nested loops [rectangular, triangular [right angled triangle only] patterns], series involving
single variable)
(Nested while and nested do while are not included).
10. Computing and Ethics
Ethical Issues in Computing.
(Intellectual property rights; protection of individual's right to privacy; data protection on the internet; protection
ps
against Span; software piracy, cybercrime, hacking, protection against malicious intent and malicious code. The
stress should be on good etiquette and ethical practices.)
INTERNAL ASSESSMENT - 100 MARKS
This segment of the syllabus is totally practical oriented. The accent is on acquiring basic programming skills quickly and
efficiently.
Programming Assignments (Class IX)
Students are expected to do a minimum of 20 assignments during the whole year to reinforce the concepts studied in the
class.
Ki
Suggested list of Assignments:
The laboratory assignments will form the bulk of the course. Good assignments should have problems which require
design, implementation and testing. They should also embody one or more concepts that have been discussed in the
theory class. A significant proportion of the time has to be spent in the laboratory.
Computing can only be learnt by doing.
the teacher-in-charge should maintain a record of all the assignments done as a part of practical work throughout the
year and give it due credit at the time of cumulative evaluation at the end of the year.
Some sample problems are given below as examples.
The problems are of varying levels of difficulty:
(i) Programs using Assignment statements. Example: Calculation of Area / Volume / Conversion of temperature /
Swapping of values etc.
(ii) Programs based on- Input through parameters. Example: Implementation of standard formula etc.
(iii) Programs based on - Input through Scanner class. Example: Implementation of standard formula etc.
(iv) Programs based on Mathematical methods. Example: larger/smaller of two numbers, cube root, square root,
absolute value, power, etc.
Computer Applications|Kips 3
(v) Programs based on if, if else, if else if ladder, nested if etc.
(a) if programs
ö Eligibility to vote
ö Vowel or Consonant
(vi)
ps
ö Programs based on slab system.
(d) Calculator
Ki
(e) Vowel or consonant etc.
(b) Programs based on printing simple series, summation of simple series, product of simple series.
(c) Prime number, perfect number, composite number, Fibonacci series. Lowest Common Multiple (LCM),
Highest Common Factor (HCF) etc.
(d) To find the biggest and smallest number from n number of entered numbers
(e) Program based on while loop like Armstrong number, Spy number, Niven number, Palindrome number, etc.
(viii) Programs based on nested loops [rectangular, triangular (right angled triangle only) patterns], series involving
single variable.
(ix) Generate first n multiples of numbers from 1 to the limit input by the user.
Important: This list is indicative only. Teachers and students should use their imagination to create innovative and
original assignments.
4 Computer Applications|Kips
EVALUATION
The teacher should use the criteria below to judge the internal work done. Basically, four criteria are being suggested:
class design, coding and documentation variable description and execution or output. The actual grading will be done by
the teacher based on his/her judgment. However, one possible way: divide the outcome for each criterion into one of 4
groups excellent, good, fair/acceptable, poor/unacceptable, then use numeric values for each grade and add to get the
total.
Class design:
Is the coding done properly? (choice of names, no unconditional jumps, proper organization of conditions, proper choice
of loops, error handling code layout). Is the documentation complete and readable? (class documentation, variable
ps
documentation, method documentation, constraints, known bugs - if any).
Excellent 20 20 20 40
Good 16 16 16 32
Fair 12 12 12 24
Poor 8 8 8 16
Note: All topics highlighted in black are additional topics as per the new ICSE syllabus 2018-19
Computer Applications|Kips 5
CONTENTS
Chapters Pages
4.
5.
“.” Dot Operator
charAt
Input in Java
ps
Scanner Class Methods
next ()
Introduc�on to Packages
Package
14
15
15
15
16-22
17
17
Advantages of Packages
Ki
Types of Packages
Creating a Package
Naming a Package
The Import Statement 19
Brain Developer 22
6. Mathema�cal Library Methods 23
cbrt() method 23
7. Condi�onal Constructs in Java 24-25
System.exit() 24
Nested If 24
8. Nested for Loops 26-46
Understanding Nested For Loops 27
Branching Statements 32
Break Statement
Continue Statement
Brain Developer 38
6 Computer Applications|Kips
LESSON 1
1
Chapter
As you have already studied the evolution of programming languages and how they came into existence, let us learn
more about Programming Paradigms. The two broadly used programming paradigms are Procedural Programming and
Object Oriented Programming.
PROCEDURAL PROGRAMMING
Procedural programming contains well-structured statements, functions and commands which are used to perform a
computational task on the data and variables. By well-structured, we mean writing functions in a progressive manner in
one program.
CHARACTERISTICS OF PROCEDURAL PROGRAMMING:
1. It provides an easier way of writing a program.
2. The program executes its statements in a step by step manner. This approach is also termed as Top-down approach.
3. The program is divided into blocks of codes called procedures or functions, where each procedure or function
performs a specific task.
ps
4. As the program flows in a sequential manner, the readability of the program increases.
5. Using functions help in code reusability.
Function - 1
Main Program
Function - 2
Ki
Function - 3 Function - 4 Function - 5
Though Procedural programming is easier to write and comprehend, it becomes quite complicated in case of large
programs, as it requires a lot of functionalities and data to be executed. Since procedural programming focuses primarily
on functions and not on data, maintaining the sequence of functions becomes the utmost priority. Data, on the other
hand, when shared among functions is declared ‘Global’. Also, debugging the code containing thousands of lines is a
tedious task for the programmers.
LIMITATIONS OF PROCEDURAL PROGRAMMING:
1. It mainly concentrates on functions, but not on the data.
2. Functions share Global data.
Let’s Know More
3. A function can access and modify the data of another function. Global data refers to
4. In case of a new requirement or modification of the program, changing data value in one the data which can be
function will not reflect in the other functions. The user needs to make necessary used across all the
changes manually, in all the functions using that data value. functions of a program.
7
OBJECT ORIENTED PROGRAMMING Let’s Know More
A programming paradigm
In real world scenarios where data security, easy debugging and efficient execution of the refers to the programming
program plays a key role for the project sustainability and maintainability, a new approach of patterns and concepts.
programming was required. This began the era of Object Oriented Programming or OOPS.
This programming paradigm concentrated on dividing the program into modules and
protecting the data. A modular approach refers to dividing the code into small reusable
fragments called functions. These fragments contain data which is used to perform specific
functionalities. The program can call these functions as and when required, without
permanently modifying the data. This approach of solving problems by scaling up from sub-
routines to the main program is termed as Bottom-up approach.
CHARACTERISTICS OF OBJECT ORIENTED PROGRAMMING:
1. An object/class once defined can be reused, thus, giving way to reusability of the code. Know the Fact
A Function or a
2. It restricts the free flow of data using data hiding techniques, thus allowing better control
Procedure is a single block
over the data.
of code which contains
3. The concept of object-oriented programming is based on real life scenarios. multiple instructions
written in a specific
4. The object oriented approach allows us to solve complex problems easily.
programming language.
5. Data security is a crucial point in OOP. It ties data closely to the function and does not
ps
allow any unauthorised modifications.
6. If data access is granted, it can be easily modified without performing data modification
in any other functions, unless required.
7. Object/class approach helps in easy debugging of the program..
LIMITATIONS OF OBJECT ORIENTED PROGRAMMING:
1. The size of the programs created with this programming approach may become larger
than the program written using procedural programming.
Let’s Know More
2. Software developed using this approach require substantial amount of pre-work and
Ki
Some examples of
planning.
Procedural Programming
3. OOP code is hard to understand if we do not have the corresponding class model and are Fortran, ALGOL,
documentation. COBOL and BASIC.
Data-A Data-B
8
KEY DIFFERENCES BETWEEN THE TWO APPROACHES
Importance Importance is given to the functions as well as Importance is given to the states and behavior
to the sequence of the function’s execution. of the objects.
Division Large program is divided into units called Entire program is divided into objects.
functions.
Data Security Data is less secured, as it contains lesser It is more secured as one of its primary features
features to protect the data. include data hiding.
Data Sharing A function can access other function's data by Only the data whose access has been granted
calling that function. can be accessed by another function.
Code Reusability Limited code reusability. Code can be reused efficiently with the help of
various advanced features provided by this
Expansion
Example
ps
It is difficult to modify, extend and maintain.
Example :- C, Fortran
methodology.
9
LESSON 1
2
Chapter
ESCAPE SEQUENCE
Java allows you to print various non-graphic characters. These characters cannot be typed directly from the keyboard,
e.g. backspace, tabs, newline, carriage return, etc. They are represented by using the escape sequences.
A character preceded by a backslash (\) is called an Escape sequence and it has a special meaning for the compiler. It is
called as an escape sequence, because the '\' (backslash) character causes the character following it to escape its normal
interpretation. For example, when we type the alphabet 'n', it displays the same character on the screen, but when it is
prefixed with '\' (backslash), it is read as an escape sequence.
When an escape sequence is encountered in a print statement, the compiler interprets it and produces the results
accordingly. For example, if you want to display quotes within quotes, you must use the escape sequence, \", on the
interior quotes. Consider the sentence: She said "Hello!" to me.
You would write:
ps
System.out.println ("She said \"Hello!\" to me.");
The following table displays the available escape sequences for various non-graphic characters used in Java:
Escape Sequence
\n
\t
\v
New Line or Line Feed
Horizontal Tab
Vertical Tab
Non-Graphic Character
\\ Backslash
Ki
\' Single Quote
\" Double Quote
\b Backspace
\f Form Feed
\0 Null Character
\r Carriage Return
\a Audible Bell (alert)
\? Question Mark
\On Octal Number (On represents the number in Octal)
\xHn Hexadecimal Number (Hn represents the number in Octal)
\uHn Unicode Character (represented through its hexadecimal code Hn).
NOTE
All escape sequences are treated as a single character. For example, ‘\xHn’ will be considered as one character.
10 Computer Applications-9|Kips
Example 1: System.out.println("Adding New Line: " + "Name: Aaryan\n"+ "Class: IX\n"+"Section: C");
Output:
Adding New Line:
Name: Aaryan
Class: IX
Section: C
As soon as "\n" is encountered, the cursor skips the current line and moves to the next line on the screen for printing the
remaining part of the output.
Example 2: System.out.println("Applying Horizontal Tab : " + " Facebook is a Social \t Networking Website");
Output:
Applying Horizontal Tab:
Facebook is a Social Networking Website
The (\t) escape sequence advances the value on the screen by providing a gap of a tab (8 spaces) between the text.
Example 3: System.out.println("Applying Carriage Return : " + "Watermelon\rfruit");
Output:
Applying Carriage Return:
fruitmelon
ps
The carriage return (\r) escape sequence shifts the cursor to the beginning of the word "Watermelon" and overwrites the
first five characters since "fruit" is five character long.
Example 4: System.out.println("Using Backspace : " + "EDUCATION IS MYY\bRIGHT");
Output:
Using Backspace:
EDUCATION IS MY RIGHT
The Backspace (\b) escape sequence deletes the previous character and shifts the cursor one space backward.
Ki
Example 5: Write a program to demonstrate the use of escape sequence.
class EscapeSequence
{
public static void main (String args[])
{
// using newline escape sequence
First line
System.out.println ("First line\nSecond line"); Second line
// using horizontal tab escape sequence A B C
D E F
System.out.println ("A\tB\tC");
System.out.println ("D\tE\tF");
}
}
11
LESSON 1
3
Chapter
Operators in Java
COUNTER VARIABLE
While using iterative loops like for, while and dowhile, a Counter Variable is used to keep the record of the number of
times a loop is executed. The value of a counter variable is incremented every time a condition is applied to it.
Counter variable needs two values in order to function :
1. Initial Value 2. Incremental Value.
The initial value is usually (not always) set to 0, and is placed outside the Ioop, whereas the Incremental value is placed
inside the loop The following example explains the same:
public class Operator
{
public static void main(String[] args)
{
int counter = 0; //Initialising Counter variable Output
System.out.println("Printing the value of the counter variable:"); Printing the value of the counter variable:
while (counter < 5) //Condition is tested 1
}
}
{
ps
counter = counter + 1;
System.out.println(counter);
}
ACCUMULATOR VARIABLE
//Incrementing Counter variable
2
3
4
5
An Accumulator variable is used to calculate the sum or product of a series of values. It is similar to the Counter variable
as it contains an Initial and Incremental value. Its incremental value is determined not through successive iterations but
Ki
by addition of a desired value to the variable in each iteration.
To comprehend this concept visualize some numbers in your head say 21, 18, 10, 11 and 40. The following figure displays,
how the sum of these numbers is calculated using an accumulator variable.
21 + 18 + 10 + 11 + 40 = 100
Accumulator
0 + 21
21 + 18
39 + 10
49 + 11
60 + 40
100
As you can observe, the accumulator is initialized to 3, and next value is added to the sum of the previous values to obtain
the final result.
12
Let us now understand the functioning of an Accumulator with the help of a loop construct.
1. Declare the accumulator variable outside the loop.
2. Before the loop begins, initialize it to zero.
3. During each loop cycle, add the value of the variable num to the accumulator variable (sum).
Program:
public class Sum
{
public static void main(String args[])
Output
{
int i=1; Current value of the accumulator is 10
int sum = 0; // Initialising Accumulator Variable Current value of the accumulator is 30
for (; i < 6; i ++) Current value of the accumulator is 60
Current value of the accumulator is 100
{
Current value of the accumulator is 150
int num=i*10;
sum += num; // Adding the value to the Accumulator variable
System.out.println("Current value of the accumulator is "+sum);
}
}
}
NEW OPERATOR
ps
The new operator is used for creating an instance of a class. Instance or object of a class is nothing but it's blueprint. The
new operator reserves memory for the program during its execution. The advantage of this operator is, that you can
create as many objects as required for the functioning of the program.
There are three steps to create an object using the New operator.
ö Declaration: In this step we declare the object.
Ki
ö Instantiation: The new operator allocates the memory to the object.
ö Initialization: The new operator then invokes the respective constructor based on the argument list.
The structure for creating an object is this:
(Class name) (Object name) = (new operator) (Class name)();
Let us understand this with a help of an example:
public class Android
{
String VersionName, MemoryCardSlot, Loudspeaker;
int PrimaryCameraMP, WeightGms ;
public void Calling()
{
// Calling Code here
}
public void Bluetooth()
13
{
//Bluetooth Code here
}
public void Camera()
{
//Camera code here
}
public void Messages()
{
//Messages Code here
}
}
From the class Android, using the new operator, we can create several instances to represent various Smartphone
models.
Android SamsungNote4 = new Android();
Android MotoG6 = new Android();
The above statements will allocate memory to the two android objects, which can store their data members individually.
VersionName VersionName
MemoryCardSlot MemoryCardSlot
Loudspeaker Loudspeaker
PrimaryCameraMP
WeightGms
“.”DOT OPERATOR
ps
SamsungNote4
PrimaryCameraMP
WeightGms
MotoG6
To access the data members of a class, the object uses the .(dot) operator. This enables us to store value in the instance
(member) variables of an object. Consider the following example for the same:
SamsungNote4.VersionName = "KitKat"; MotoG6.VersionName = "Lollipop";
Ki
SamsungNote4.MemoryCarSlot = "Yes"; MotoG6.MemoryCardSlot = "Yes";
SamsungNote4.Loudspeaker = "Yes"; MotoG6.Loudspeaker= "Yes";
SamsungNote4.PrimaryCameraMP = "16"; MotoG6.PrimaryCameraMP = "13";
SamsungNote4.WeightGms = "176" MotoG6.WeightGms= "145"
The .(dot) operator stores the provided values corresponding to the member variable as shown in the Figure.
PrimaryCameraMP 16 PrimaryCameraMP 13
SamsungNote4 MotoG6
14
LESSON 1
4
Chapter
next()
The next () method is used to read the next token from the Scanner Object. It scans the token and returns it to the calling
statement in the String format.
The next() function can read the input until it encounters a space i.e., it cannot read two words separated by a space. It
also places the cursor in the same line after reading the input.
Let’s Know More
Syntax: String variableName = scannerObject.next ();
Regular expression is a
import java.util.Scanner; special sequence of
public class NextMethod
{
{
ps
public static void main (String args[])
class CharAtMethod
{
public static void main(String args[])
{
String s = "Welcome! To Kips";
char ch = s.charAt(5);
System.out.println(ch);
ch = s.charAt(0);
System.out.println(ch); m
} W
}
15
LESSON 1
5
Chapter
Input in Java
INTRODUCTION TO PACKAGES
In object-oriented programming, a class library is a collection of prewritten classes or coded templates which simplify
the job of a programmer. In the previous chapters, we have used many built-in functions of Java, such as println() and
print(). While using these functions, we have used the keyword, System before the function call. As per usage, we can
interpret that all these methods are members of the ‘System’ class. The ‘System’ class is predefined in Java and is
automatically included in the programs.
The Java environment has a huge library of built-in classes that contain pre-defined functions to support the
input/output operations and String handling operations. These functions are also responsible for, the development of
network and graphical user interface.
Library class in an integral part of a package. A Java package is a collection of similar types of built-in classes (library
classes), and sub packages, which provide most of the functionality that comes with Java, so it is extremely important to
PACKAGE
ps
learn the art of using them. Java library classes are also called standard Java classes.
Some most commonly used packages are java.lang, java.util, java.i.o, java.awt, java.net, etc.
In real life programming scenarios, users design very large applications that have many classes in it. While declaring
multiple classes in a program, namespaces must be managed properly.
A namespace ensures that all identifiers within it must have unique names, so that they can be easily identified. In order
Ki
to manage the namespace, Java provides the mechanism of creating Java Packages.
A Java Package can be considered as a collection of Java classes that are grouped on the basis of their functionality.
While designing large applications, programmers must ensure that their source code does not conflict with the source
code of other programmers. For example, if two programmers define two distinct classes with the same name, then we
have a conflict in the program. This issue can also arise when a programmer chooses a class name, which already exists in
16
the Java library. For example, if we create a class with the name, Math, then this class will conflict with the Math class of
the Java library.
To solve this problem, we have the concept of packages in Java. We can define packages, in which, classes can be grouped
on the basis of their functionality. Each package has its own namespace and the classes are placed within that
namespace. Every identifier must have a unique name in the namespace. Outside the namespace, we can have another
class with the same name. Hence, by using packages, we can define multiple classes that have the same name, provided
these classes belong to different packages.
Another useful feature of package is that it provides a better control over the code. Without using packages, it is very
difficult to manage hundreds of classes in a project. However, categorizing these classes into packages makes it easier to
manage classes, their definitions and the code.
ADVANTAGES OF PACKAGES
ö Packages group related classes, so that they can be managed effectively.
ö Whenever a class is required, it can be used by importing the parent package.
ö We can declare multiple classes with the same name, but in different packages.
ö Encapsulation can be implemented by using packages.
TYPES OF PACKAGES
These packages are already present within the Java language. All the built-in classes are grouped together in packages,
like java.lang, java.io, java.applet, etc. These packages (except java.lang) are imported by the programmers as per their
requirement. The java.lang package is the only package that gets invoked automatically for all Java programs. This
package provides the basic functionality of Java language. The classes, such as String, StringBuffer, Math, System and
Ki
Wrapper are part of the java.lang package.
These packages are defined by the user and stored with unique names. These packages are imported in Java programs by
using the import command.
CREATING A PACKAGE
To create a package in Java, we write the keyword package, followed by the name of the new package. This statement
should be the first statement in the program file.
Syntax: <Package> <Package Name>;
For example: package shapes;
NAMING A PACKAGE
We can define multiple classes with the same name in Java; provided the classes exist in different packages. In a program,
the classes are identified by their qualified names. The qualified name of a class includes the class name along with the
reference of the package that contains the class.
17
Once we create and store the Circle class in the shapes package, the fully qualified name of this class will be
shapes.Circle. Thus, by using the package name along with the class name, one can uniquely identify the class.
The symbol * imports all the classes that are present in the specific package.
You may even use the class without importing any class. For this you will have to use the fully qualified name of the class.
import shapes.Circle;
Example
Circle c1 = new Circle ();
ps
You may also use the fully qualified name of the class and use it as:
Example 1: Let us create a project to demonstrate the creation and use of packages. In this project, we will create a
package with the name shapes and create three classes named as Triangle, Rectangle and Circle in it. We will create
another class; but outside the package. It will import the package and use its classes.
Step 1: Create a new project and choose New Package Step 2: Enter a name for the new package and click the Ok
Ki
option in the Edit menu. It will display a dialog box asking button. The package icon will appear in the project window
you to enter a name for the new package. as shown in the Figure.
18
Step 3: To open the package, double-click on its icon. The project will open and the project icon will display the text <go
up> on it, indicating that the package is open.
Step 4: Create three different classes named as Triangle, Rectangle, and Circle in the shapes package. To add a new class
in a package, click on the New Class button.
The Create New Class dialog box appears. Enter the name of the new class and click on OK button.
Project Window
ps
Ki
Writing Code for the Triangle Class
19
Step 7: Write the code segment for Circle class.
Step 8: Once you have created the classes, the class icons Step 9: After creating the classes in the package, close the
will appear with the package icon. package by choosing Close option in the Project menu. You
will be reverted to the project window.
ps
Ki
Package and its Classes in the Project Window Closing the Package
Step 10: Now you are outside the package. Let us create a Step 11: Create a new class by clicking on the New Class
class outside the package which will import the shapes button. Specify the name UsePackage to the new class and
package in it. write the code as shown here. The class icon will appear in
the project window.
20
Step 12: Execute the program by right-clicking on the Step 13: The output of the program will be displayed in the
UsePackage class icon and choosing the main() method. BlueJ's "terminal" window.
ps
In the program output, you can see that the class UsePackage has used the functions of Triangle, Rectangle, and Circle
classes that are in the shapes package. Hence, we can say that a package is a collection of classes which can be used in a
program by importing the package.
Some common Packages in Java are as follows:
1. java.applet - It is a Java applet package
2. java.net - It is a Java Networking package
3. java.util - It is a Java utility package
4. java.awt - Its is a java Abstract Window Toolkit package
Ki
5. java.io - It is a Java Input/Output package
6. java.lang - It is a Java language package
Now we shall discuss some common java.util packages :
a) java.util.Data - It helps in representing a specific instant in time. Let us show its execution via following example:
import java.util.Date;
public class Kips
{
public static void main(String args[])
{
Date x = new Date(); // Initializing the Date object Today's date is Tue May 29
14:50:03 IST 2018
System.out.println("Today's date is " + x);
}
}
b. java.util.Calendar - It helps in maintaining a set of calendar fields such as YEAR, MONTH, DAY, HOUR, MINUTE,
SECOND, MILLISECOND. It also helps in manipulating the mentioned fields.
21
In this class, we use a method 'Calendar.getInstance()', which in turn returns a Calendar Know the Fact
instance by using the default time zone and locale. A token is the smallest
element of a Java
NOTE program. It can be either a
java.util.calendar is an abstract class, thus can't be instantiated keyword, a variable, a
constant, a special
Let us understand its execution via following example: character or an operation
etc.
import java.util.Calendar;
public class MyFirstCalendar
{
public static void main(String args[])
{
Calendar x = Calendar.getInstance();
System.out.println("Year: " + x.get(Calendar.YEAR)); //It will print the current year
System.out.println("Day: " + x.get(Calendar.DATE));
System.out.println("Hour: " + x.get(Calendar.HOUR)); Year: ..................
System.out.println("Minute: " + x.get(Calendar.MINUTE)); Day: ...................
Hour: .................
System.out.println("Second: " + x.get(Calendar.SECOND)); Minute: .............
} NOTE
}
ps Second: .............
When you the execute the program, the Calendar.getInstance() method fetches the current date and time of the system.
BRAIN DEVELOPER
Ki
A. Fill in the Blanks:
1. A …………………………… is a collection of similar types of built-in classes.
2. …………………………… and …………………………… packages are used for the input /output operation.
3. A …………………………… ensures that all the identifiers withing it must have unique names.
22
LESSON 1
6
Chapter
cbrt() method
This method is used to calculate the cube root of the value provided. It always returns the output in a double format and
accepts both positive as well as negative numbers as its arguments.
import java.lang.*;
Output
public class MathFunction Cuberoot of (64.0)=4.0
{ Cuberoot of (10.0)=2.154434690031884
Cuberoot of (-125)=-5.0
public static void main(String[] args)
ps
double x = 64;
double y = 10;
}
Ki
}
23
LESSON 1
7
Chapter
b) exit(1) or exit(-1) or any other non-zero value : This indicates unsuccessful termination of the program.
{
ps
public static void main(String args[])
{
System.exit(0); // exists the program
Ki
}
else
System.out.println(i); // prints the value of variable from i = 0 to 5
}
}
}
NESTED IF
When we code an if statement inside another if statement, it is termed as Nested if statement. It is a conditional
statement, which is used when more than one condition is to be evaluated sequentially in a program. The statements are
executed from the top to the bottom, checking whether each condition meets required criteria or not. If the condition
evaluates to true, then it executes the block of statements associated with it, else it moves to evaluate the next
condition.
NOTE
The inner if(s) statement must always be terminated before the outer if(s) statement.
24
Nested if can be represented in 3 ways:
if nested inside if part if nested inside else part if nested inside both if and else part
if (expression1) if (expression1) if (expression1)
{ Body of if; {
if (expression2) else if (expression 2)
Statement 1; { Statement 1;
else if (expression2) else
Statement 2; Statement 1;
Statement 2;
} else
}
else Statement 2;
else
Body of else; }
{
if (expression 3)
Statement 3;
else
Statement 4;
}
Example 1: Program that will accept three numbers from the user, and checks the greatest number.
import java.util.Scanner;
class LargestNo
{
{
ps
public static void main (String args [])
}
System.out.println ("Enter 3 numbers:");
a = sc.nextInt();
initializing the first, second and third variable
b = sc.nextInt();
as a, b and c respectively
c = sc.nextInt();
Ki
if (a > b)
{
if (a > c)
System.out.println (a +" is the largest");
else
System.out.println (c +" is the largest");
} Enter 3 numbers:
else 34
56
{ 77
if (c > b) 77 is the largest
System.out.println (c +" is the largest");
else
System.out.println (b +" is the largest");
}
}
}
25
LESSON 1
8
Chapter
In the previous chapter, you have learned that loops are used to execute a set of statements repeatedly. During
programming, sometimes when you need to repeat the actions of a loop a number of times, in this scenario, you need to
place a loop construct inside the body of another looping construct, this is called nesting.
When you "nest" two loops, the outer loop controls the number of times the inner loop iterates. Once the cycle of the
inner loop is completed the control steps up to the outer loop. Nested loops can have more than two loops, executed one
after the other in a specific pattern.
Let us understand the nested loop concept, with the help of the following example.
NOTE
Consider every month to have 30 days.
A month is completed after a time span of 30 days and a year is completed after a time span of 12 months. When a month
ps
begins, the outer loop is read by the system, the control enters the inner loop and it iterates through 30 days. Once the
iteration is completed, the control goes back to the outer loop. The outer loop denotes the beginning of January, trailed
by the happenings of all the 30 days. The outer loop steps up to the month of February, followed by a sequence of 30 days
(the inner loop). Thus, the process repeats a number of times for each repetition of the outer loop.
Example
for (int month=1; month<=12; month++)
{
Ki
for (int day=1; day<=30; day++)
{ Inner Loop
Note that the outer loop is executed only 12 times (no. of months) but the inner loop is executed 12*30 times (assuming
30 days in each of the 12 months).
26
The Flowchart explains the structure of a Nested loop:
Initialization
False Increment/
Condition1
Decrement
True
False Increment/
Condition2
Decrement
True
End for
NOTE
Example
ps
Nested loops are important as they help in framing programs related to matrix, 2-D arrays, 2-D pattern printing etc.
It is not necessary, that a For loop can only contain a nested For loop. It can also contain a nested while or a do while loop.
class Iterations
{
Outer loop iteration =1
System.out.println("i = " + i + "; j = " + j);
i = 1; j = 1
} i = 1; j = 2
Outer loop iteration =2
} i = 2; j = 1
i = 2; j = 2
} Outer loop iteration =3
i = 3; j = 1
} i = 3; j = 2
27
When both the loops (outer and inner) get successfully executed, the control then shifts to execute the following
statement/s present in the program.
Lets understand the execution of this program through a DryRun.
DryRun: The outer loop is executed thrice, where the value of the control variable i range from 1 to 3. Whereas, the inner
loop executes depending on the value of control variable j which ranges from 1 to 2. The inner loop repeats a number of
times for each repetition of the outer loop.
Step 1: Value of i is initialized to 1. After that the test condition is evaluated. If the condition evaluates to true, the control
enters the body of the outer for loop.
Step 2: The value of j is initialized to 1. After initialization, the control checks the test condition. If the test expression
evaluates to true, the control enters the body of the inner for loop.
Step 3: Now the inner loop will execute two times. Printing the values of i and j respectively, in each of iteration.
Step 4: Once the execution of the inner loop is completed, the control is transferred to the test expression of the outer
loop. If the condition results true, control enters the outer loop incrementing the value of i, i.e., i + 1 = 2. After validating
the test condition, control comes to the inner loop.
Step 5: Variable j controlling the inner loop will be initialized to 1 and the loop will be executed twice.
Step 6: Once the condition becomes false, the control exits the inner loop and goes back to the outer loop.
Step 7: Again it executes the update expression i.e., i++ and validates the test expression.
Steps
1st iteration
2nd iteration
rd
3 iteration
ps
Step 8: If the condition evaluates to true, the sequence is repeated, else control exits the outer for loop.
This is the working of a nested for loop.
Let us learn some patterns which can be created using the nested For loop.
Ki
public class StarPyramid
{
Example public static void main(String args[])
{
for (int row = 1; row <= 7; row++) The Inner For loop repeats till the value of
{ col (column) is less than or equal to the
value of row.
for (int col = 1; col <= row; col++)
{
System.out.print("*");
*
} This statement brings the **
System.out.println(); cursor to the next line ***
****
} *****
} ******
} *******
28
public class NumberPyramid Let's Know More
The '*' is printed in the
{
descending order of the
Example public static void main(String args[]) column index and
ascending order of the
{ The loop will progress from row index.
for(int row = 1; row<=5; row++) col=1 to the iteration value of the
row and repeats four times.
{
for(int col = 1; col <= row; col++)
{
System.out.print (row+ " ");
}
System.out.print("\n"); Printing the value of the outer
} loop control variable row.
1
22
System.out.println(" "); 333
} 4444
} 55555
NOTE
Example
{
ps
Number of rows in the pattern depicts, the number of times the outer loop repeats.
29
int value = 8; This loop is repeated five times
for(int row = 1; row <= 5; row++) as the value of row ranges
{ from 1 to 5.
As the value of the outer variable row increases, the iterations of the inner loop decreases. Thus, it prints the "<>" symbol
in a descending fashion.
PRACTICE TIME
Print the following patterns using the Nested For loop.
00 01 02 03 1 54321
Example
10
20
30
ps
11
21
31
{
Ki
System.out.println("Pyramid of numbers in Java:");
for (int row = 0; row < 5; row++) This loop prints iterates from
0 to 4 and repeat five times.
{
for (int space = 0; space < 5 - row; space++)
{ This statement prints the spaces to
System.out.print(" "); produce a centre aligned pyramid.
}
This loops, iteration depend on the iteration
for (int col = 0; col <= row; col++) value of control variable row. In this case, it
{ iterates from 0 to 4.
30
public class DualPattern
{
Example public static void main (String args[])
{
int n = 6;
for(int row = 0; row < n; row++)
{
for(int col = 0; col < row; col++)
{ This loop prints the periods
System.out.print("."); '.' in increasing order the
row index from row = 0 to 4
}
This loop prints the stars
for(int col = 0; col < (n-row); col++) '*' in the decreasing order the
row index from col = 0 to 5
{
System.out.print("*");
} * * * * * *
System.out.println(); • * * * * *
}
}
ps
}
Example
public static void main(String args[])
Ki
{
int i , j, total = 0;
for(i = 1; i <= 2; i++)
{
int factorial = 1;
for (j = 1; j <= 2; j++)
{
factorial = factorial *j;
}
total = total + factorial;
}
System.out.println("Sum of the factorial series is "+ total);
Sum of the factorial series is 4
}
}
31
public class Tables
Tables
{ 1 * 1 = 1
Example
public static void main(String args[]) 1 * 2 = 2
1 * 3 = 3
{
1 * 4 = 4
int i= 1, j= 1; 1 * 5 = 5
1 * 6 = 6
System.out.println("Tables");
1 * 7 = 7
for(i = 1; i <= 2; i++) 1 * 8 = 8
{ 1 * 9 = 9
1 * 10 = 10
for(j = 1; j <= 10; j++)
{ 2 * 1 = 2
2 * 2 = 4
System.out.println(i + "*" + j + "=" + ( i *j ));
2 * 3 = 6
}
}
} 2 * 4 = 8
System.out.println(""); 2 * 5 = 10
2 * 6 = 12
} This statement prints the This statement prints
2 * 7 = 14
current value of the the product of the
} 2 * 8 = 16
NOTE
} ps control variables. control variables.
2
2
*
*
By default the control executes only one statement mentioned under the for loop. If multiple statements are to be
executed, it should be enclosed within the curly braces.
9
10
= 18
= 20
BRANCHING STATEMENTS
BREAK STATEMENT
Ki
Break statement is used to shift the control instantly, from the current loop structure. Whenever the break statement is
encountered inside a loop, the loop gets terminated for rest of the iterations and the control shifts to the next statement
following the loop.
As we have already been acquainted with the working of the Break statement while using the Switch Case, let us get an
insight to its working with respect to the for, while, and do while loop.
32
Break statement is of two types:
1. Unlabelled Break Statement 2. Labelled Break Statement
1. Unlabelled Break Statement
This statement is widely used while programming. When the Unlabelled Break Statement is encountered within a loop,
the control terminates the loop containing it and shifts to the next immediate command following the loop. It can be
used with switch, for, while and do-while loops.
Syntax:
for(…)
{
//loop statements
break;
}
{
Example
{
ps
public static void main(String args[])
break;
NOTE
At fifth iteration, since Break statement is encountered, the loop gets terminated and the control comes to the main method.
33
Unlabelled Break Statement in Nested For loop
In nested for loop, the break statement terminates the loop it has been declared in and the program control resumes to
the next statement contained within the outer loop. It means that if the break statement is declared inside the inner for
loop it stops the execution of the current loop and passes the control to the outer for loop.
Syntax:
for(…)
{
//loop statements
for(…)
{
break;
}
}
Let us understand the working of the break statement with the help of an example:
ps
public static void main (String args[])
{
// The loop iterates twice from i= 1 to 2
for (int i = 1; i <= 2; i++)
{
System.out.println ("Iteration value of Outer loop: " + i);
// The loop iterates two times, where the value of j ranges from 1 to 2
Ki
for (int j = 1; j <= 3; j++)
{
// Terminates the inner loop at 3rd iteration.
if (j == 3)
{
break;
}
System.out.println ("Iteration value of Inner loop: "+j);
}
Iteration value of Outer loop: 1
System.out.print("\n"); Iteration value of Inner loop: 1
} Iteration value of Inner loop: 2
Control comes to the outer loop Iteration value of Outer loop: 2
}
when the Break executes Iteration value of Inner loop: 1
} Iteration value of Inner loop: 2
34
2. Labelled Break Statement
Sometimes, when we need to terminate the execution of the outer loop or any other enclosing loop, the Labelled break
statement is used. The loop should be labelled for it to work.
Syntax:
<label>:
for(…)
{
//loop statements
for(…)
{
break <label>;
}
}
Example
{
ps
public static void main (String args[])
{
outer:
for (int i = 1; i <= 3; i++)
{
The loop iterates twice from i= 1 to 2
as the control encounters the labelled
break statement at the third iteration.
35
CONTINUE STATEMENT
The Continue statement is mostly used within the control loops. When this statement is encountered inside a loop, the
control jumps to the beginning of the loop for next iteration, skipping the execution of the remaining statements inside
the loop’s body.
This statement is particularly used when you want to continue the loop but do not want the rest of the statements(after
the continue statement) present in the loop body to execute for the current iteration.
The difference between these two statements is that, the break statement terminates the execution of the current loop
and shifts the control to the following statement, whereas continue statement skips the current iteration and continues
to execute the next iteration of the loop.
It is of two types:
1. Unlabelled Continue Statement
2. Labelled Continue statement
1. Unlabelled Continue Statement
This is the most common form of using this control statement. It is used when, we want to skip the execution of
remaining statement(s) (occurring after the continue statement in the code) of the innermost for, while and do-while
loop.
Syntax
{
for(…)
ps
//loop statements
continue;
}
36
Let us understand this with the help of an example:
}
}
ps
}
System.out.print("]\n");
Sometimes, when we wish to skip the execution of the statements mentioned inside the outer loop and step up the
control to execute the next iteration, in such case, Labelled Continue Statement is used.
Ki
Syntax:
<label>:
for(…)
{
//loop statements
for(…)
{
continue <label>;
}
}
37
{
FirstForloop:
// The loop iterates two times for i= 1 and 3
for (int i = 1; i < 4; ++i)
{
// The loop iterates thrice for j= 1 to 3
for (int j = 1; j < 4; ++j)
Control is transferred to the outer
{ loop labelled as 'FirstForloop'
if (i == 2) to perform the next iteration
{
continue FirstForloop;
}
System.out.println ("i = " + i + " ; j = " + j); i=1;j=1
i=1;j=2
}
i=1;j=3
} i=3;j=1
} i=3;j=2
i=3;j=3
}
A.
ps
BRAIN DEVELOPER
Multiple Choice Questions:
1. Nested loops can have more than ……………………….. loops
Ki
a. 2 b. 3 c. 4 d. 5
2. In the following program, how many times the inner loop will get executed?
for (int j=1; j<=3; j++)
{
for (int k=1; k<=5; k++)
{
//Some Code
}
}
a. 8 times b. 11 times c. 15 times d. none of these
3. Select the Inner for loop which executes the control till the value of the control variable col is less than or equal
to the value of row?
a. for (int col = 0; col > row; col++)
b. for (int col = 1; col < row; col++)
c. for (int col = 0; col <= row; col++)
d. for (int col = 1; col < row; col++)
38
4. Which of the following loop iterates five times from row=1 to 5?
a. for( int row = 0; row <= 5; row++)
b. for( int row = 1; row = 5; row++)
c. for( int row = 0; row < 5; row++)
d. for( int row = 1; row <= 5; row++)
5. By default, the control executes how many statement(s) mentioned under the for loop?
a. One b. Two c. Three d. Four
6. Which of the following statements terminate the execution of the current block?
a. do while b. break c. continue d. return
7. Write the name of the statement that is used to skip a section of code in a loop.
a. continue b. Looping c. return d. break
8. How many times will the message,”Welcome to the world of Java”, get printed?
int x;
for ( x =1; x <= 10; x ++ )
{
if ( x < 5 )
break;
}
else
continue;
a. Infinite times
b. 4 times
ps
System.out.println (”Welcome to the world of Java”);
c. 11 times
d. None of these
39
D. Solved Programs:
1. Write a program to display the product of control variables i and j, where value of j should never be greater than
the value of i.
Ans. public class NumberTriangle
{
public static void main (String args [])
{
outer:
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 10; ++j)
{ 0
01
if (j > i)
024
{
0369
System.out.println ( );
0 4 8 12 16
continue outer; 0 5 10 15 20 25
} 0 6 12 18 24 30 36
System.out.print (" "+( i * j )); 0 7 14 21 28 35 42 49
} 0 8 16 24 32 40 48 56 64
} 0 9 18 27 36 45 54 63 72 81
2.
}
}
ps
Create a program that will accept a number from the user and display whether the number is a Prime
Number or a Composite Number.
Ans. public class PrimeOrComposite
{
public static void main (int num)
{
if (num < 2)
{
Ki
System.out.println (+num+ "is neither Prime nor Composite number.");
}
else
{
int i;
int div = 0;
for ( i = 2; i < num; i++ )
{
if ( num % i == 0 )
{
div = 1; // if any division is successful, the div variable will be initialized to 1.
break;
}
}
if (div == 0)
{
System.out.println (num+ " is a Prime Number.");
}
else
40
{
System.out.println (num + " is a Composite Number.");
}
} 17 is a Prime Number.
}
}
3. Write a program to find the sum of following series.
Sum = 1! + 2! + 3! +…………..+ n!
In this program, the value n will be accepted from user.
Ans. import java.util.Scanner;
public class SumOfSeries
{
public static void main (String args [])
{
int sum = 0;
int n;
Scanner sc = new Scanner(System.in);
System.out.println ("Please enter the value of n:");
n = sc.nextInt ();
System.out.println ("n = " +n);
int i;
{
ps
System.out.print ("Elements of the series are:");
int fac = 1;
int j;
for (j = 1; j <= i; j++)
{
fac = fac * j;
Ki
}
System.out.print (fac+ "," ); Please enter the value of n:
sum = sum + fac; 6
n=6
} Elements of the series are:
System.out.print (""); 1, 2, 6, 24, 120, 720,
Sum of series= 873
System.out.println ("Sum of series=" +sum);
}
}
4. Study the inverted triangle as displayed and write a program to print it. [ICSE] - 2009
Inverted Triangle:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
41
Ans. public class ReverseNumberTriangle
{
public static void main (String[]args)
{
System.out.println ( "Inverted Triangle" );
for (int i = 5; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print (i + " ");
}
System.out.println ();
}
}
}
5. Write a program to generate the following output. [ICSE] - 2015
Combo Pattern:
*
*#
*#*
*#*#
*#*#*
42
6. Using the switch statement, write a menu driven program for the following: [ICSE] - 2016
(i) To print the Floyd's triangle (ii) To display the following pattern
1 I
2 3 IC
456 ICS
7 8 9 10 ICSE
11 12 13 14 15
For an incorrect option, an appropriate error message should be displayed.
Ans.
import java.util.*;
public class MenuProgram
{
public static void main (String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println ("1.Floyd's triangle");
{
switch (ch)
case 1:
ps
System.out.println ("2. Triangle pattern");
System.out.print ("Enter your choice:");
int ch = sc.nextInt ();
int k = 1;
for (int i = 1; i <= 5; i++)
Ki
{
for (int j = 1; j <= i; j++)
{
System.out.print (k + " ");
k++;
}
System.out.println ();
}
System.out.println ();
break;
case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j <= i; j++)
{
System.out.print (s.charAt(j)+" ");
}
43
System.out.println();
}
break;
default:
System.out.println("You have entered an invalid choice");
}
}
}
7. Write a program to print the pattern displayed below. [ICSE] - 2017
Inverted Character Pyramid
A B C D E
A B C D
A B C
AB
A
Ans. public class InvertedCharacterPyramid
{
public static void main (String[]args)
{
System.out.print("Inverted Character Pyramid");
//For loop with character argument
for(char ch= 'E'; ch>= 'A'; ch--)
{
//For loop with character argument
8.
}
}
{ ps
for(char v= 'A';v <= ch; v++)
System.out.print("\n");
}
}
44
primeno = false;
break;
}
n++;
Enter a number: 30
}
As 2 is a factor of 30.
while (n <= mid); It is not a Prime number
if (primeno == true)
System.out.println (num + "is a prime number!");
}
}
9. Write a program to print series of 5n+2, but skip the multiples of 2. Print upto first 10 terms of the series.
Ans. public class Series
{
public static void main (String[]args)
{
int i= 1;
int value = 0;
System.out.println("The series is: ");
for(i=1; i<= 10; i++)
}
{
}
ps
value =5*i +2;
if( value % 2 ==0)
continue;
System.out.println(value);
The series is :
7
17
27
37
47
}
Ki
E. Find the Output:
1. In the following program, determine how many times the loop will be executed and what will be the output of
the program segment? [ICSE] - 2011
int num=200;
while (true)
{
if(num<100)
break;
num=num-20;
}
System.out.println(num);
Ans. Loop will execute seven times.
Output will be 80
2. Write the output of the following program code: [ICSE] - 2015
char ch;
int a = 97;
do
{
45
ch = (char) a;
System.out.print(ch + " ");
if(a%10==1)
break;
++a;
}
while(a<=100);
Ans. a b c d
3. Study the following code snippet and answer the following questions:
for(int num=5 ;num<=20 ; num+=5)
{
if(num%3==0)
break;
else
if(num%5==0)
System.out.println(num);
continue;
}
(i) Write the output of the program.
(ii) How many times does the body of the loop gets executed?
Ans: Output: 5
F.
1.
2.
10 ps
Loop will be executed three times
[ICSE] - 2008
3. What are the different types of break statements? Explain with an example.
Ki
4. What are nested loops? Explain with the help of an example.
2. 1 2 3 4 5
1 2 3 4
1 2 3
1 2
1 2 3
1 2 3 4
1 2 3 4 5
46
3. *
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
1 1
1 2 1
6.
1 3 3 1
1 4 6 4 1
ps
Write a program to print the series mentioned below:
47
Kips ICSE School Books
ps
Ki