Computer NOTES ICSE 10 2024

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

COMPLETE CLASS 9 &

10TH PROGRAMMING
IN 1 VIDEO
Follow me on
Instagram to Get
Updates !

@pranaymishrack
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)

ONLY FOR 150


STUDENTS !
The first thing you do in coding:
Creating a CLASS
By creating a class we create a memory location in Computer's memory.
For eg:
class CIE

CIE CIE

Class

Computer's memory
CLARIFY KNOWLEDGE
Class Formation Basic !
Now, inside a class, we need memory allocations for variables to
store data.
Syntax to create a variable:
data_type variable_name=constant/value
For eg:
String var="cons";

var cons

Variable
[String]

Class
CLARIFY KNOWLEDGE
DATA TYPES
D The means to recognize or identify an entity/entities and their
operations are known as data types.

To store different types of values/data we use different data types.


Integer Data: There are 4 data types for storing integer data, they
are arranged in ascending order of their range:
byte - short - int - long
Real Data: There are 2 data types for storing real data, they are
arranged in ascending order of their range:
float - double
Character Data: We use char data type to store characters i.e.
data enclosed in single inverted commas(' ').

CLARIFY KNOWLEDGE
String Data: We use String data type to store characters i.e. data
enclosed in double inverted commas(" ").
Boolean Data: We use boolean data type to store boolean data i.e.
true and false.

Now we've learned how to store a value in a variable let's learn


how to print it!

CLARIFY KNOWLEDGE
HOW TO PRINT?
You can print via 2 ways:
System.out.print() : This statement prints the sentence and
keeps the controller in the same line.
System.out.println() : This statement prints the sentence
and brings the controller in the next line.

System.out.print("I'm Pranay Mishra: ");


System.out.println("Founder of Clarify Knowledge");
System.out.print("Welcome to Code Is Easy");
-> I'm Pranay Mishra: Founder of Clarify Knowledge
Welcome to Code Is Easy

CLARIFY KNOWLEDGE
Let's store a value in a variable and print it.
int a=7;
String str="Prana";
char ch='y';
double b=1.0;
System.out.print(str+ch+b+a);
-> Pranay1.07

CLARIFY KNOWLEDGE
ESCAPE SEQUENCE CHARACTERS
D The character constant which begins with backslash(\) followed by
one letter that reflects the corresponding output during execution of
code or program is knowns as escape sequence character or non-
graphic character.
For eg: '\a\ , '\n' , '\t' , etc.

\n - New Line
\t - One tab space
\' - Prints single inverted commas(') in output
\" - Prints double inverted commas(") in output
\\ - Prints backslash (\) in output

Enter key is also known as Carriage-return key.

One tab space means 5 spaces(cursor shifts 5 spaces).


CLARIFY KNOWLEDGE
TYPE CONVERSION
If we want to use a data in real data type variable that is in integer
type then we need to change its data type and this process is known
as type conversion.

There are two ways of type casting:


Implicit Type conversion - automatic
Explicit Type conversion - forced

CLARIFY KNOWLEDGE
IMPLICIT TYPE CONVERSION
Implicit type converion works on this hierachy:
byte
char
short
int
long
float
double
It's just like the reactivity series of chemistry, here the lower data types
are more powerful, they will change the above ones into their data
type.
char + int = int
int + long =long
int + double = double CLARIFY KNOWLEDGE
EXLICIT TYPE CONVERSION
It is forced coversion of data types and is also known as Type
Casting.
For eg:
int a,float b,char c;
d= (char)(a+b*c);
char ch='A';
System.out.print((int)ch);
-> 65

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
SIMPLE if() statement
Syntax:-
if(condition or relational statements)
{
Statement-block;
}

CLARIFY KNOWLEDGE
if-else() statement

Syntax:-
if(condition or relational statements)
{
if-code;
}
else(conditional or relational statements)
{
else-code;
}

CLARIFY KNOWLEDGE
NESTED if() statement
Syntax:-
if(condition-1)
True
{ Condition-1 Statement-1
Statement-1
if(condition-2) False
{
False Condition-2
Statement-2; Exit

}
True
}
Statement-2

CLARIFY KNOWLEDGE
NESTED if-else() statement
Syntax:-
if(condition-1)
{
if(condition-2)
{
Statement-2;
}
else()
{
Statement-3;
}
}
else()
{
Statement-3;
} CLARIFY KNOWLEDGE
Flowchart of nested if-else() statement

CLARIFY KNOWLEDGE
Input System
Input Using Parameters
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
INPUT USING INITIALIZATION
D The process of assigning data or actual values to a declared variable
is known as initialization.
This process is basically not taking input from the user but assigning
the values in the variables during writing the code.

INPUT USING SCANNER


D The class that allows to input or read primitive data
types(int,short,float,etc.) and strings is known as Scanner Class.
Syntax :- Scanner variable_name = new Scanner(System.in)
-> Scanner sc = new Scanner(System.in);
-> Scanner ob = new Scanner(System.in);
-> Here ob and sc are the variable names.

CLARIFY KNOWLEDGE
INCREMENT(++) AND DECREMENT(--) OPERATORS
The increment operator increases the value by 1 and the decrement
operator decreases the value by 1.
PREFIX NOTATION
The presence of an increment or decrement operator before the
operand or variable is known as prefix notation. For eg: ++A or --A
It first changes the value then uses it. (change-then-use rule)
int A = 3;
int B = 10;
System.out.println(++A);
System.out.println(--B);
Output:-
4
9 CLARIFY KNOWLEDGE
Now lets make a calculator using Scanner!
Step 1:
CREATE A CLASS

Step 2:
CREATE A SCANNER OBJECT

CLARIFY KNOWLEDGE
Step 3:
CREATE A SCANNER OBJECT

Step 4:
ASK FOR USER'S CHOICE

CLARIFY KNOWLEDGE
Step 5:
ASK FOR NUMBERS

Step 6:
CREATE CONDITIONS FOR PROPER WORKING

CLARIFY KNOWLEDGE
Step 7:
JUST PRINT THE RESULT NOW

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
Math Class
Functions Purpose Suntax Examples

Returns absolute value of a


Math.abs(-73)
abs() numeric data by ignoring Math.abs(argument)
-> 73
the sign

Returns the square root of Math.sqrt(81)


sqrt() Math.sqrt(argument)

CLARIFY KNOWLEDGE
a positive number -> 9.0

Used to find the power of a Math.pow(5,3)


pow() Math.pow(arg,power)
numeric data -> 125.0

It rounds of the number to Math.round(1.5) -> 2


round() Math.round(arg)
closest integer value Math.round(3.2) -> 3
Functions Purpose Suntax Examples

Returns truncated value of


an argument by rounding Math.rint(30.35) -> 30.0
rint() Math.rint(argument)
it off to greater number if iit Math.rint(5.5) -> 6.0
is 0.5 or more.

CLARIFY KNOWLEDGE
floor() Returns the lower number Math.floor(argument) Math.floor(1.8) -> 1.0

ceil() Returns the upper value Math.ceil(argument) Math.ceil(1.2) -> 2.0

Returns the largest from Math.max(36,40.5)


max() Math.max(arg1,arg2)
two arguments ->40.5
Functions Purpose Suntax Examples

Returns the smallest from Math.min(10,17)


min() Math.min(arg1,arg2)
two arguments ->10

Returns the cube root of Math.cbrt(125) -> 5.0


cbrt() Math.cbrt(argument)

CLARIFY KNOWLEDGE
the number Math.cbrt(-8) -> -2.0

Generates a random Math.random()


random() Math.random()
number between 0.0 to 1..0 -> 0.7134361215296077
Q √a+b

Q (1 / 3)a³ + (1 / 4)b³

CLARIFY KNOWLEDGE
Q S = ut + 1/2at²

Q d = √ l² + b²

CLARIFY KNOWLEDGE
Q Give the output of the following equations.
if x =-9.99 , calculate Math.abs(x);
if x = 9.0 , calculate Math.sqrt(x);

CLARIFY KNOWLEDGE
Q Give the output of the following functions.
Math.floor(=126.349)

Math.max(45.6 , 17.3)

Math.min(-0.0 , 0.0)

Math.pow(4 , 3)

Math.sqrt(625)

Math.ceil (-12.56)

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
SWTICH CASE
SWITCH STATEMENT
D The switch keyword is a selection statement that allows to transfer the
program control on the matching case depending upon the value of
variable or expression.
The switch is also known as multiple (or multiway) branching
statement or user's choice ctatement.

CLARIFY KNOWLEDGE
KEYWORDS OF SWITCH-CASE
switch: It is used to transfer the program control to the matching case
depending on the value of the variable or expression.
case: It contains one or more executable statements that end with a
break statement.
break: It is a jump statement that terminates the execution of the
current case and comes out of the body of switch.
default: It is the last statement of the switch body and executes if the
matching case is not found.

CLARIFY KNOWLEDGE
SYNTAX
switch(value or expression)
{
case constant-1:
statement-block-1;
break;
case constant-2:
statement-block-2;
break;
case constant-N:
statement-block-N;
break;
default:
statement-block-default;
}
CLARIFY KNOWLEDGE
Q Write a menu-driven to check whether a number is
(i) even or odd
(ii) multiple of 17 or not
(iii) two-digit number or not.

CLARIFY KNOWLEDGE
Find the output:
Q
switch(op)
{
case 1: System.out.println("Ck");
case 2: System.out.println("op!");
break;
case 3: System.out.println("Hustle Hard!");
break;
default: System.out.println("Code Is Easy!");
}
op=1

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
LOOPS
FOR ( ) LOOP
D The loop that executes one or more statements upto a finite limit is
known as for ( ) loop.

SYNTAX :
Keyword for ( Initial-Value ; Test Condition ; Update-statement )
{
Statement-blocks;
}

CLARIFY KNOWLEDGE
WHILE ( ) LOOP
D The loop that executes one or more statements till the condition is TRUE
and terminates the iteration when the condition is FALSE .
SYNTAX :
while ( expression or condition or relational expression)
{
Statements-block
}

CLARIFY KNOWLEDGE
DO-WHILE ( ) LOOP
D The loop that executes one or more statements till the condition is TRUE
and terminates the iteration when the condition is FALSE, is known as do-
while( ) loop.

SYNTAX :
Keyword do
{ SEMICOLON COMPULSORY
Statement-block
}
Keyword while( condition or relational expression);

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
Q Java Program to Display Even Numbers From 1 to 100
using "while loop"

CLARIFY KNOWLEDGE
Q Java Program to Display Even Numbers From 1 to 100
using "for loop".

CLARIFY KNOWLEDGE
Q Write a program in Java to display the following pattern:
1
22
333
4444
55555

CLARIFY KNOWLEDGE
Q Write a program in Java to display the following pattern:
54321
4321
321
21
1

CLARIFY KNOWLEDGE
Q Write a program in Java to display the following pattern:
3
44
555
6666
77777

CLARIFY KNOWLEDGE
Q Write a program in Java to display the following pattern:
5
44
333
2222
11111

CLARIFY KNOWLEDGE
Q S =1 * 2 + 2 * 3 + 3 * 4 + 4 * 5 + 5 * 6 + 6 * 7 + 7 * 8 + 8 * 9 + 9 * 10

CLARIFY KNOWLEDGE
Q S = 1 + 1/ 2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 +1/10

CLARIFY KNOWLEDGE
Q S = a/2 + a/3 + a/4 + a/5 + a/6 + a/7 +a/8 + a/9 + a/10

CLARIFY KNOWLEDGE
Q S = 1+2/1*2 + 1+2+3/1*2*3 + 1+2+3+4/1*2*3*4 + 1+2+3+4+5/1*2*3*4*5
up to "n"terms

CLARIFY KNOWLEDGE
Q Accept a number and check whether it is perfect or not.
A number is said to be perfect if sum of all its factors excluding the
numbers itself is equal to the original number

CLARIFY KNOWLEDGE
Q Accept a number and check whether the number is a buzz
number or not.
A number is said to be a buzz number if it either ends with 7 or is
divisible by 7.

CLARIFY KNOWLEDGE
Q Write a program to print digits and count of digits in the number.

CLARIFY KNOWLEDGE
Q Accept a number and check whether the number is palindrome or
not.
If a number and its reverse form is same then the number is a
Palindrome number.

CLARIFY KNOWLEDGE
Q Accept a number and check whether the number is neon or not.
If sum of digits of square of a number is equal to the original
number then the number is said to be Neon.
For eg :- 9
9*9 = 81 and 8+1=9

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
CLARIFY KNOWLEDGE PRESENTS

Class 10 (COMPUTER)
Thoery
INTRODUCTION
So far, you have studied the methods and the way they work in Java. Now
you will be learning a different type of method. It is known as a
constructor and its most distinguishing feature is that it is named after
the class it is in. Let us find out more about the constructor.

CLARIFY KNOWLEDGE
CONSTRUCTORS
A constructor is a special member method of a class without a return
type. It is used for initialising and constructing the data members of an
object when it is created. It is automatically called (invoked) when the
object is created using new operator. It cannot be invoked by the user like
normal methods.

CLARIFY KNOWLEDGE
CHARACTERISTICS
A constructor will have the same name as that of the class.
A constructor does not have a return type not even void.
A constructor cannot be static or final.
A constructor must be declared public (if it has to be accessed outside
the class).
It is automatically called (invoked) when an object is created.

CLARIFY KNOWLEDGE
NEEED OF A CONSTRUCTOR
A constructor is used for initialising and constructing the data members of
an object with legal values when it is created. Data members are mostly
declared as private members, to implement data hiding and abstraction.
Due to this, data members cannot be initialised outside the class with
values. So, constructors are used for initialising the objects implicitly as
they are created.

CLARIFY KNOWLEDGE
DECLARING AND DEFINING
Being a method, it also gives the programmer the ability to define,
declare and modify. Since, a constructor has no return type (not even
void), it also provides the programmer with the liberty to define a
constructor with or without a parameter.
A simple constructor is created using the new operator followed by the
name of the class.
Syntax:
<access specifier> class_name (parameter list/void)
{
Data_member1 = value1 ;
Data_member2 = value2;
}

CLARIFY KNOWLEDGE
EXAMPLE:
class Book
{ int bookno;
String name;
float price;
public Book() //constructor is created, having same name Book as
{ bookno = 0; that of its class name Book, with public access specifier
name = "ABC"; and no return type.
price=0.0
} }

CLARIFY KNOWLEDGE
TYPES OF CONSTRUCTORS
The main function of a constructor is to initialise the data members of an
object while it is created. Constructors can be broadly categorised into
two categories based on the parameters it takes:

Default constructor : A constructor that takes no parameters.

Parameterised constructor : A constructor that takes one or more


parameters.

CLARIFY KNOWLEDGE
DEFAULT CONSTRUCTOR/NON PARAMETERISED CONSTRUCTOR
A constructor that takes no parameters is called a default constructor. It
will have the name of the class and have no return type. If you do not write
a constructor in your program, the compiler will supply a default
constructor and initialise values with the default values of the primitive
data types i.e. integer variables to zero, floating point variables to 0.0 and
String to null.
Syntax:
class_name()
{
Data_member1 = value1;
Data_member2 = value2;
}

CLARIFY KNOWLEDGE
PARAMETERISED CONSTRUCTOR
Constructor that takes one or more parameters or arguments is called as
a parameterised constructor. Such a constructor will accept values and
initialise the data members with the corresponding values. There is no
limitation to number of parameters.

Syntax:
class_name (type1 val 1, type2 val 2...)// parameter list
{
Data_member1 = val 1;
Data_member2 = val 2;
}

CLARIFY KNOWLEDGE
'THIS' KEYWORD
'this' keyword is used within a constructor to refer to the current object. It
is actually a reference to the object that invokes the constructor. In fact,
even if you do not use the this keyword, the compiler normally implicitly
converts it by prefixing this to the data members.

CLARIFY KNOWLEDGE
constructor member methods

name: always similar to class name name: according to user


return type: no return type return type: void or valid
need: to initilalise member need: to avoid repetition and to
variables increase code reusability.

CLARIFY KNOWLEDGE
CONSTRUCTORS WITHIN CONSTRUCTORS USING 'THIS'

Constructors can be chained together by invoking a constructor from


within another constructor. The this keyword is used to invoke another
constructor from within the class. When constructors are chained this
way, the control just moves from one constructor to the other till the data
members are initialised and the object is fully constructed.

CLARIFY KNOWLEDGE
String !
Integer - Number
Integer - Word Parameter

String
Taking the Input of String
Pre described
String A = "apple";
From Scanner
String B = sc.nextLine();
Indexing and Length of the String
String A = "Pranay Mishra"
Note :- Indexing always starts from 0 and ends with the
one smaller than the length of the string.
Length function
int length = A.length();
length = 13;

INDEXING
Pranay Mishra
Character at the Position.
String A = "Pranay Mishra"
Note :- It picks the Character as per the Indexing done.
char ch = A.charAt(8);
char ch = ?
FUNCTIONS OF THE STRING
equals()

equalsIgnoreCase()
FUNCTIONS OF THE STRING
compareTo()

compareToIgnoreCase()
FUNCTIONS OF THE STRING
indexOf()

lastIndexOf()
FUNCTIONS OF THE STRING
substring() -
if the last index is given , it is
excluded from the substring.
FUNCTIONS OF THE STRING
concat() -

Alternative
temp = "apple";
ch = 'a';
temp = temp + ch;
temp = ch + temp;
FUNCTIONS OF THE STRING
replace();
FUNCTIONS OF THE STRING
endsWith();

startsWith();
FUNCTIONS OF THE STRING
toLowerCase();

toUpperCase();
FUNCTIONS OF THE STRING
toLowerCase();

toUpperCase();
FUNCTIONS OF THE STRING
trim()

valueOf()
WAP TO PRINT THE NUMBER OF CHARACTER IN THE WORD
WAP TO PRINT THE FIRST WORD OF THE NAME AND SURNAME.
PRANAY MISHRA - P.M.
WAP TO CHECK WHETHER A WORD IS PALINDROME OR NOT.
computer - cpmpvtfr
Do this.
ARRAY !
collection of a similar data and working as an single entity.

For example: int A[10] represents the array of the integer data type
that can hold 10 values. This memory location of A[10] will be
A[0], A[1], A[2], . . A[9] .

CLARIFY KNOWLEDGE
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
Initializing an Array.
int a[] = {1,2,3,4,5}
a[0] = 1;
a[1] = 2; Indexing of array starts from 0 always.
a[2] = 3; 1,2,3,4,5 No. of elements in an array is equal to the length of the array.
The indexing of the array always ends with the length -1.
a[3] = 4; 0 1 2 3 4
a[4] = 5;

CLARIFY KNOWLEDGE
Input of an Array.
int m[] = new int[10];
int l = m.length;

for (int i =0 ; i<l ; i++)


{
m[i] = sc.nextInt();
}

CLARIFY KNOWLEDGE
WAP to collect 10 Integers and print the Sum of them.

CLARIFY KNOWLEDGE
Linear Search !
Write a program to search for an integer value input by the user in
the list given below using linear search technique. If found display
"Search Successful" and print the index of the element in the array,
otherwise display "Search Unsuccessful".
{75, 86, 90, 45, 31, 50, 36, 60, 12, 47}

CLARIFY KNOWLEDGE
import java.util.Scanner;

public class KboatLinearSearch


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);

int arr[] = {75, 86, 90, 45, 31, 50, 36, 60, 12, 47};
int l = arr.length;
int i = 0;

System.out.print("Enter the number to search: ");


int n = in.nextInt();

for (i = 0; i < l; i++) {


if (arr[i] == n) {
break;
}
}
if (i == l) {
System.out.println("Search Unsuccessful");
}
else {
System.out.println("Search Successful");
System.out.println(n + " present at index " + i);
}
}
}
CLARIFY KNOWLEDGE
Output

CLARIFY KNOWLEDGE
Binary Search !
Write a program to perform binary search on a list of integers given
below, to search for an element input by the user. If it is found
display the element along with its position, otherwise display the
message "Search element not found".
5, 7, 9, 11, 15, 20, 30, 45, 89, 97

CLARIFY KNOWLEDGE
import java.util.Scanner;

public class KboatBinarySearch


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


int arr[] = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};

System.out.print("Enter number to search: ");


int n = in.nextInt();

int l = 0, h = arr.length - 1, index = -1;


while (l <= h) {
int m = (l + h) / 2;
if (arr[m] < n)
l = m + 1;
else if (arr[m] > n)
h = m - 1;
else {
index = m;
break;
}
}
if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " + index);
}
}
}

CLARIFY KNOWLEDGE
Output

CLARIFY KNOWLEDGE
Bubble Sort !
Write a program to input 15 integer elements in an array and sort
them in ascending order using the bubble sort technique.

CLARIFY KNOWLEDGE
import java.util.Scanner;

public class KboatBubbleSort


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = 15;
int arr[] = new int[n];

System.out.println("Enter the elements of the array:");


for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}

//Bubble Sort
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
System.out.println("Sorted Array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
} CLARIFY KNOWLEDGE
Output

CLARIFY KNOWLEDGE
Selection Sort !
Write a program to input and sort the weight of ten people. Sort and
display them in descending order using the selection sort technique.

CLARIFY KNOWLEDGE
import java.util.Scanner;

public class KboatSelectionSort


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double weightArr[] = new double[10];
System.out.println("Enter weights of 10 people: ");
for (int i = 0; i < 10; i++) {
weightArr[i] = in.nextDouble();
}

for (int i = 0; i < 9; i++) {


int idx = i;
for (int j = i + 1; j < 10; j++) {
if (weightArr[j] > weightArr[idx])
idx = j;
}

double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}

System.out.println("Sorted Weights Array:");


for (int i = 0; i < 10; i++) {
System.out.print(weightArr[i] + " ");

}
} CLARIFY KNOWLEDGE
output

CLARIFY KNOWLEDGE
CLARIFY KNOWLEDGE PRESENTS

2D Array
CLARIFY KNOWLEDGE

Single dimensional array: It has a sigle subscript


int ar[]=new int[3];
Double dimensional array: It has double subscript
int ar[][]=new int[3][3];
CLARIFY KNOWLEDGE

subscript
of array
[ ]
00

10

20
0 1 2
01

3 4 5
11

6 7 8
21
02

12

22
CLARIFY KNOWLEDGE

Row column

[ ] [ ]
00

10

20
0 1 2
01

3 4 5
11

6 7 8
21
02

12

22
00

10

20
0 1 2
01

3 4 5
11

6 7 8
21
02

12

22
CLARIFY KNOWLEDGE

logic To enter elements/digits in the matrix


for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
Outer loop {
ar[i][j]=in.nextInt();
} inner loop
}
CLARIFY KNOWLEDGE

logic To print the matrix


for(int i=0;i<3;i++)
{
it prints the row for(int j=0;j<3;j++)
and as the loop {
terminates,
System.out.print(ar[i][j] + “ “);
it starts }
printing the next
row in the next System.out.println();
line }
and the process repeats until the outer loop is terminated
CLARIFY KNOWLEDGE

Output:
CLARIFY KNOWLEDGE

LEFT DIAGONAL RIGHT DIAGNOAL

[ ] [ ]
00

10

20
0 1 2
01

3 4 5
11

6 7 8
21

when i==j
02

12

22
00

10

20
0 1 2
01

3 4 5
11

6 7 8
21
02

12

22

when i+j==2
left diagonal elements are found right diagonal elements are found
CLARIFY KNOWLEDGE

LOGIC:
CLARIFY KNOWLEDGE

Output:
CLARIFY KNOWLEDGE

Program for sum of elemnts of matrix:


CLARIFY KNOWLEDGE

Output:
MIC Kholo
Doubt Pucho SERIES | ICSE 10 2024

One on One Interactive


Includes Notes, DPP’s & eBooks
Slides attached with classes
Covers all subjects
All subjects by pranay Bhaiya
Includes Toppers test series worth Rs749
Includes Mentorship (Daily)
ONLY FOR 150
STUDENTS !
Some Important
Programs !
QUESTION -(3)
(i)
Define a class called with the following specifications:
Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased

Member methods:
void accept(): Accept the name and the price of the item
using the methods of Scanner class.

void calculate(): To calculate the net amount to be paid by a


customer, based on the following criteria:
Price. Discount
1000 – 25000 5.0%
25001 – 57000 7.5 %
57001 – 100000. 10.0%
More than 100000 15.0 %

void display(): To display the name of the item and the net
amount to be paid.

Write the main method to create an object and call the above
methods.
import java.util.Scanner;
public class Eshop
{
private String name;
private double price;
private double disc;
private double amount;

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter item name: ");
name = in.nextLine();
System.out.print("Enter price of item: ");
price = in.nextDouble();
}

public void calculate() {


double d = 0.0;

if (price < 1000)


d = 0.0;
else if (price <= 25000)
d = 5.0;
else if (price <= 57000)
d = 7.5;
else if (price <= 100000)
d = 10.0;
elsed = 15.0;

disc = price * d / 100.0;


amount = price - disc;

public void display() {


System.out.println("Item Name: " + name);
System.out.println("Net Amount: " + amount);
}

public static void main(String args[]) {


Eshop obj = new Eshop();
obj.accept();
obj.calculate();
obj.display();
}
}
QUESTION -(8)
Define a class to overload the method display as follows:
void display( ): To print the following format using nested loop
1
12
123
1234
12345

void display(int n): To print the square root of each digit of the given number.
Example:
n = 4329
Output – 3.0
1.414213562
1.732050808
2.0
import java.util.Scanner;

public class KboatMethodOverload


{
public void display()
{
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print(j + " ");
}
System.out.println();
}
}

public void display(int n)


{
while( n != 0)
{
int d = n % 10;
System.out.println(Math.sqrt(d));
n = n / 10;
}
}

public static void main(String args[])


{
KboatMethodOverload obj = new KboatMethodOverload();
Scanner in = new Scanner(System.in);

System.out.println("Pattern: ");
obj.display();

System.out.print("Enter a number: ");


int num = in.nextInt();
obj.display(num);

}
}

You might also like