YPCC ICSE 9th COMP NOTES
YPCC ICSE 9th COMP NOTES
Blue-J
FEATURES:
✓ Well Planned Notes
✓ Mini Test Papers
ICSE Class – 9th ✓ Smart Practice Notes
Computer Applications (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/
Contents
Ch. No. Chapters Page No.
2 1. Introduction to JAVA Basics 3
2. How To Download Blue-J & Java 7
3. Values and Data Types 8
4. Operators in Java. 25
1. How to solve Java Expressions 29
5. Input in Java 36
6. Mathematical Library Methods. 43
7. Conditional Statements in Java(if).
1. if Statement 50
2. Switch Statement 57
8. Iterative / Loop Constructs in Java. 62
1. for loop 63
2. While loop 66
3. Do-while loop 68
9. Nested for loops 70
1. Jump statements (break, continue). 75
10. OOPS(Object Oriented Programming) in Java. 77
11. Important Question & Answers 84
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→2
Ch 1 : Introduction To JAVA Basics Sub: Computer Application
JMD HGGM
ICSE Class 9th
Java Byte Code → Java source code is converted in to an intermediate code after compilation. This code is known as Byte
5 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
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→5
Ch 1 : Introduction To JAVA Basics
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Types of Java
6 OOP, Interface, Package, Exception
CORE JAVA Handling, Threading, Applet,
JDBC, Beans etc.
JAVA Servlet, Networking, RMI,
ADV. JAVA
Swing, CORBA, JSP etc.
Hierarchy of Java
Developers
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→6
Ch 2 : How To Download Blue-J & Java
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Downloads
Blue J → Blue J is an Integrated Development Environment (IDE) for executing programs written in Java. It has a viewer,
7 editor & debugger.
Video Link:
https://www.youtube.com/watch?v=eVHF4K-E6XQ&list=PLzeLu0s-QMy_yQv8sG2Ou96lsbHXlPdLv&index=46
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→7
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Data → Raw facts and figures. Eg. (‘a’, ‘5’, ‘#’ etc).
Program → Collection of instructions (data). Delimiters are the
Software → Collection/set of programs. special characters.
They are used as -,
Data Types ; , : , ?, ., ( ), { }, [ ],
etc.
String→ String is a collection of characters. It encloses with double quotes. Eg: “123”, “Ram”, etc
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→9
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Tokens
Token: Token is a smallest individual unit of a program. Tokens are building blocks of Java. Types of tokens are:
11 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
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→11
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Token→ Literals
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.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→12
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Variable
Variable is a name given to memory location to store data by user. On the other hand, It is the quantity which can change
13 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.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→14
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Q1→ Find addition and product of given numbers. Q3→ WAP to swap to numbers.
17
class Swap
class FirstPro {
{ public static void main()
public static void main(String args[ ]) {
{ int A = 10, B = 20, C;
int a = 10, b = 20, 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);
Q2→ Write the SOP line to print 10 + 20 = 30 in above Program }
}
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→17
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Q4→ Find addition and product of given numbers. Q6→ WAP to swap to numbers.
18
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→18
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Q7→ Find addition and product of given numbers. Q9→ WAP to swap to numbers.
19
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→19
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Programs
Q10→ WAP to input employee name and his salary of a month and print his annual salary.
20 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→20
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Escape sequences are non-graphical characters that Escape Sequences Non-Graphical Character
21
control the way how data gets printed on output device.
It always begins with a backward backslash ‘\’. \n New line
Eg: \n, \t, \” etc. Outputs \t Horizontal tab
System.out.println(" Hello \n Java "); Hello \” To print double quote
Java
System.out.println(" Hello \t Java "); Hello Java \’ To print single quote
System.out.println(" Hello \” Java "); Hello “ Java \\ To print backslash
System.out.println(" Hello \\ Java ");
\b Backspace
\0 Null
\r Carriage return
\f Form feed
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→21
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→22
Ch 3 : Values & Data Types
JMD HGGM
ICSE Class 9th Sub: Computer Applications
Type Conversion
Conversion of one datatype to another datatype is called type conversion.
23
There are two types of type conversions:
1. Implicit type conversion / type coercion 2. Explicit type conversion / narrowing conversion / type casting
Type Conversion
Explicit Conversion of Literals
24 Examples
float f = 0.123F
double d = 23.34D
int a = 12;
long b = 12L
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→24
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
Operators
Operators:- Operators are special symbols which represents computation. They are applied on operand(s), which can be
25 values or variables.
Operand:- Operands are variables or constants on which operations are performed by the operator.
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→25
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
Operators
Arithmetic Operators:
26 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→26
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
Operators
Logical Operators: They are used for combining various ! (NOT) Operator: The not operator works by
27 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→27
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
Arithmetical Expression(s)
Precedence of Operators:
29
Operators Precedence Associativity 8. Bitwise AND &
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→29
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
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
Operators ++ and --
31
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.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→31
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→32
JMD HGGM
Ch4: Operators in Java ICSE Class 9th Sub: Computer Applications
Operators ?:
Ternary operator:
34 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;
35
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→35
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
Q4→ Find addition and product of given numbers. Q6→ WAP to swap to numbers.
37
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);
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→37
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
Programs
Q7→ WAP to input the time in seconds. Display the time after converting them into hours, minutes and seconds.
38 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)
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→38
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→39
}
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
Programs
Q1→ Find addition, subtraction, product and division of given Q2→ WAP to swap to numbers.
40 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→40
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
Java Programs
Q1→ WAP to input your name, gender and age and print these details.
41 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→41
JMD HGGM
Ch5: Input in Java ICSE Class 9th Sub: Computer Applications
42
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→42
ICSE Class 9th
JMD HGGM
Ch6: Mathematical Library Methods Sub: Computer Applications
Methods / Functions
Methods/Functions are subprograms or small block of code which perform specific action. Or
43 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.
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→43
ICSE Class 9th Sub: Computer Application
JMD HGGM
Ch6: Mathematical Library Methods
The library methods (functions) are the in – built methods created by the developers. These predefined functions help the
44
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.
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→46
ICSE Class 9th Sub: Computer Application
JMD HGGM
Ch6: Mathematical Library Methods
Math.random( )
47 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)
49
JMD-HGGM
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→49
Ch 7 : Conditional statement in Java ICSE Class 9th Sub: Computer Application
JMD HGGM
If statement - Questions
54
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 ).
System.exit(0)
System.exit(0)
56 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→56
Ch 7 : Conditional statement in Java ICSE Class 9th Sub: Computer Application
JMD HGGM
switch statement
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.
switch statement
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→58
Ch 7 : Conditional statement in Java ICSE Class 9th Sub: Computer Application
JMD HGGM
switch statement
switch statement
switch statement
Switch - Questions
61
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.
These statements are used to perform a set of instructions repeatedly while the condition is true. iteration statements are
62 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.
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→62
ICSE Class 9th Sub: Computer Application
JMD HGGM
For loop
63
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”);
There are different variations / types in the ‘for’ loop given below:
65 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++ );
While loop
While loop
66
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→66
Ch 8: Iterative Constructs in Java ICSE Class 9th Sub: Computer Application
JMD HGGM
While loop
Do …. While loop
Do…While loop Q2→ WAP to input name and age of persons. Continue the
68
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.nextLine();
Eg1: }while(i <= 10);
age = sc.nextInt();
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.next().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. }
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.
It first checks the condition & then executes the statements. It is used when number of iterations is unknown.
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→69
Ch 9: Nested Loop ICSE Class 9th Sub: Computer Application
JMD HGGM
NESTED LOOP
70
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→70
Ch 9: Nested Loop ICSE Class 9th Sub: Computer Application
JMD HGGM
Pattern Questions
Pattern Questions
71
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
72
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→72
Ch 9: Nested Loop ICSE Class 9th Sub: Computer Application
JMD HGGM
Pattern Questions
73
Find Outputs
76
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→76
ICSE CLASS - IX
Object Oriented Programming
JMD
HGGM Oops In Java Computer Application
77
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.
JMD
HGGM Components of OOP Computer Application
78
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.
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.
JMD
HGGM Creating Class & Object Computer Application
79
JMD
HGGM OOPS IN JAVA Computer Application
80
JMD
HGGM OOPS IN JAVA Computer Application
81
JMD
HGGM OOPS IN JAVA Computer Application
82
INHERITANCE
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.
JMD
HGGM OOPS IN JAVA Computer Application
83
84
Q1→ Name any two POP(Procedure Oriented Programming and OOP(Object Oriented Programming languages?
Q1→ An act of using essential features without including the background detail is called ________________
86
Q2→ In an OOP, the importance is given to ________________
Q3→ Wrapping of data and functions together as a single unit is called_________________
Q4→ An ________________ has a unique identity which contains some characteristics and behaviour.
Q5→ The objects may communicate with each other through _____________________
Q6→ In POP, The Global data are loosely attached to the ___________________
Q7→ The process by which a class acquires the properties from another class is known as_______________________
Q8→ In OOP, using a function for many purposes is termed as________________________
Q9→ Two categories of low level languages a)__________________________, b)__________________________
Q10→ Two Procedure oriented languages a) _____________________________b)_________________________
Q11→ Two Structure oriented programming languages a)________________, b)_______________
Q12→ Two examples of data abstraction in your daily life a)________________, b)_______________
Q13→ Two Examples of real world objects a)________________, b)_______________
Q14→ Two Basic principles of OOP a)________________, b)_______________
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q1→ Find errors and write the correct statements. Q7→ Explain the Floating Point Datatype.
87
public main(void)
{ Q8→ Mention any two rules for naming an identifier.
int x, y=10;
x=y++; Q9→ Rewrite the following statement using conditional
system.out.println(“Result = ”, (x+y)); operator..
} if(temp>=35)
System.out.print(“No Deduction”);
Q2→ Name the different kinds of operators in Java. else
System.out.print(“25% tax deduction”);
Q3→ What is a keyword.
Q10→ Explain two characteristics of Java.
Q4→ Given the following expressions:
a) ans=100 b) ans==100 Q11→ What is the purpose of ‘new’ keyword.
How do the differ?
Q5→ Explain the ternary operator with an example? Q12→ What will be the output of m after executing:
Q6→ Evaluate the following expressions: m += m-- + --m + m++ + 2;
a) if x=10, y=5, find z if m = 5, before evaluation.
z = x++ - --x + ++y;
b) if p=20, q=15, find r Q13→ What are identifiers?
r = ++q + p + q++ + ++p + p;
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q14→ What will be the default initial values of:- Q17→ Write the conditional statement for the following
88 a) An integer variable decision making situations.
b) A float variable If value of X is greater than 10 then increment the
c) A boolean variable value of y by 1 otherwise decrement the value of Y
d) A double variable by 5.
e) A String variable
f) A char variable Q18→ Assume x=5, y=3 and state the output.
g) long variable System.out.print( ( x+y > x*2 ) ? x++ : y );
h) byte variable
i) short variable Q19→ Give the output:
if( a>b || a!=b )
Q15→ What will be the size and range of following datatypes c = ++a + --b;
a) float System.out.print(c + ” ” + a + ” ” + b);
b) byte a) Assume a = 5 and b = 2
c) double b) Assume a=0 and b=0
d) char
e) boolean Q20→ Explain, with the help of an example, the purpose of
f) short default in a switch statement?
g) long
h) int
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q21→ Identify errors in the following statements and Q26→ A variable can store _____ value/values at a time.
89 correct them: a) 1 b) 2
a) int x+5 =y; c) any no. of d) 3
b) s- -=10
Q27→ When all cases do not match the value of the switch
Q22→ The character set used in java is named as: Expression, the flow of execution in transferred to _______
a) ASCII code b) Unicode atatement:
c) Extended code d) None a) case b) break
c) default d) if-else
Q23→ A set of characters is enclosed in:
a) ‘ ’ b) “ ” Q28→ Two arithmetic expressions can be compared with
c) : : d) ; ; if statements using :
a) Arithmetic operator b) relational op
Q24→ Write the ASCII codes for: c) Ternary operator d) Logical Op
a) A to Z
b) a to z Q29→ Evaluate the value of z if x=2 and y=1
c) 0 to 1 z= --x + y++ + ++y + x--;
d) space
Q25→ Which of the following is not a keyword? Q30→ What is the use of rint() and max() methods of Math
a) false b) or Class.
c) void d) true
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q31→ What will the function return: Q35→ Name one data type for the following along with
90 a) Math.ceil(9.3); Its default value.
b) Math.max(-4.3, -4.6); a) integer data
double x=7.9, y=7.5; b) single letter
c) System.out.print(Math.min(Math.floor(x),y)); c) decimal point
d) System.out.print(Math.max(Math.ceil(x),y)); d) true/false
e) set of characters
Q32→ State the use and return type of the following
mathematical functions: Q36→ Differentiate between:
a) abs() a) postfix and prefix increment operators
b) exp() b) unary and binary operators
c) random() c) = and ==
d) log()
Q37→ Explain with syntax if – else – if construct
Q33→ Write a valid java statement to perform the given task:
a) to generate random numbers between 0 and 1 Q38→ What is the purpose of default and break in
b) to find the square root of 144 Switch case.
Q34→ Find the value of m when Q39→ What is a block? Give examples.
a) double m=Math.abs(Math.max(-47.5, -46.8));
b) double m=Math.pow(Math.ceil(7.2), Math.floor(3.8));
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q40→ Rewrite the following statement using switch case: Q43→ Write a conditional statement to check whether
91 if(ch==‘A’) the sum of a and 2b is greater than product of a and b
System.out.print(“Very Good”); and the difference of a and b is less than a/2.
else if(ch==‘B’ || ch==‘C’)
System.out.print(“ Good”); Q44→ Predict the output when:
a) ans=350 b) ans=450
else if(ch==‘D’)
int ans, sum, x=150;
System.out.print(“fair”);
sum = x + ans > 500 ? 600 : 200;
else System.out.println(sum);
System.out.print(“Unsatisfactory”);
Q45→ Write the java statements for the following
Q41→ Debug the following code a) accept an integer number from the console
char ch = Z; b) add it to the existing total of 1200 to update the
if(ch==‘Z’ || ch==‘z’) total.
System.out.println(“Last Alphabet”);
System.out.println(“Consonant”); Q46→ What are the types of casting shown in the
else following example:
a) double n=18.5;
System.out.println(“Not the Last Alphabet”);
int m = (int)n;
b) int n = 75;
Q42→ Mention two situations where switch statement is preferable long m = n;
Over if-else statement.
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
Q47→ Rewrite using ternary operator. Q50→ Give the output of:
92 if(amount<10000) a) choice=2
rate=0; b) choice=5
else switch(choice)
rate=12; {
case 1:
System.out.println(“Polymorphism”); break;
Q48→ Write valid java statement for the expression.
case 2:
a=0.05 – 2*y^3/x – y; System.out.println(“Inheritance”);
case 3:
Q49→ a) int y = 14; System.out.println(“Abstraction”); break;
int z = ++y*(y-- + --y); default :
find the value of z and y System.out.println(“Encapsulation”);
b) int a = 5; }
int b = a + a-- % 5 * ++a + 5*a—;
find the value of a and b.
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
93
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
94
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
95
Section B
Q1→ Write a program to accept two numbers and display sum, product, difference, quotient and remainder.
96
Q2→ Write a program to accept marks of 5 subjects calculate and display total and percentage.(each subject out of 100)
Q3→ Write a program to accept Principle amount, rate of interest and time period. Calculate and display simple interest and
amount.
Q4→ Write a program to accept Temperature in Fahrenheit and convert to Celsius. ( C=(F-32)*5/9 )
Q6→ Write a program to accept Radius of a circle. Calculate and display area and circumference of the circle.
Q7→ Write a program to accept two numbers check and display the smaller of the numbers.
Q8→ Write a program to accept a number. Check and display if it is a positive or a negative number.
Q9→ Write a program to accept name and age of a person. Check and display if he/she is eligible to vote. (Age 18 and
above are eligible).
Q10→ Write a program to accept a number. Check and display if it is even or odd.
Section B
Q1→ Write a program to accept student’s name, class and division, roll no, total marks out of 1000. Calculate percentage.
97 Assign grade and give remark accordingly. (Percentage between 100 and 80, grade A remark- Excellent, between 80 and 60
grade B remark- Good, between 60 and 40 grade C remark- Satisfactory, less than 40 grade D remark- Must work hard)
Example of Output:
NAME: Ved Gandhi
CLASS & DIV : 9A
ROLL NO. : 34
TOTAL MARKS: 765
PERCENTAGE: 76.5
GRADE : B
REMARK : GOOD
Q2→ Design a class with name Employee. Accept the name and the basic pay of the employee and find his/her gross pay.
DA =25%, HRA=15%, PF=8.33%(all percent of basic pay). Net pay=basic pay+DA+HRA
Gross pay= Net pay-PF
Q3→ Write a program to accept 3 numbers. Check and display whether they form a Pythagorean Triplet.
Q4→ Write a program to accept a character, check and display if it an uppercase character, a lowercase character, a digit or
a special character.
Q5→ Write a menu driven program to accept 2 numbers and an operator. Calculate and display according to user’s choice.
Section B
Q6→ A cloth showroom has announced the following discounts based on the total cost of the items purchased.
98
TOTAL COST DISCOUNT
Less than Rs.2000 5%
Rs.2001 to 5000 25%
Rs. 5001 to Rs.10000 35%
Above Rs. 10000 50%
Write a program to accept the total cost and to compute and display the amount to be paid by the customer after availing the
discount.
Q7→ Write a program to accept the monthly sales of a salesman. Compute the commission and the travelling allowance of
the salesman as per the tariff given below. Display the total income of the salesman. (commission + travelling allowance)
SALES COMMISSION TRAVELLING ALLOWANCE
Less than Rs.5000 Nil 2%
Rs.5001 to Rs.15000 10% 5%
Rs. 15001 to Rs.25000 15% 8%
Rs. 25001 to Rs.35000 20% 10%
Rs.35001 to Rs.45000 25% 12%
Above Rs. 45000 30% 15%
Section B
Q8→ Write a menu driven program to calculate and display area and perimeter of circle, square, rectangle and triangle.
99
Q9→ Write a menu driven program to convert from one unit to another.
1) Kilobyte to byte
2) Meter to inches
3) Gallon to litres
4) Fahrenheit to Celsius
Q10→ Write a menu driven program to display the result of the following based on the number entered by the user.
1) Natural logarithm of the number
2) Absolute value of the number
3) Square root of the number
4) Random number
Q11 → WAP to print following menu.
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice __
Enter two number ___ ____
Result is ___
Practice Makes Perfect WWW.YPComputerClasses.in 7798161873 p→99
ICSE Class 9th Sub: Computer Application
JMD HGGM
Java Important Questions and answers
Section B
Q12→
100
Q13→
Section B
Q14→
101
Q15→ Write a program to accept the monthly sales of a salesman. Compute the commission and the travelling allowance
of the salesman as per the tariff given below. Display the total income of the salesman.
(commission + travelling allowance)
SALES COMMISSION TRAVELLING ALLOWANCE
Less than Rs.5000 Nil 2%
Rs.5001 to Rs.15000 10% 5%
Rs. 15001 to Rs.25000 15% 8%
Rs. 25001 to Rs.35000 20% 10%
Rs.35001 to Rs.45000 25% 12%
Above Rs. 45000 30% 15%
Section B
Q16→
102
Section B
Ans1→import java.util.*; else if(per>60)
103 class student {
{ grd='B';
public static void main() rem="Good";
{ }
int clss,rn,div,tot; else if(per>40)
char grd; {
String name,rem; grd='C';
double per; rem="Satisfactory";
Scanner sc=new Scanner(System.in); }
System.out.println("Enter students name, class, division, else
roll no and total marks out of 1000"); {
name=sc.nextLine(); grd='D';
clss=sc.nextInt(); rem="Must work hard";
div=sc.next().charAt(0); }
System.out.println("NAME: "+name);
rn=sc.nextInt();
System.out.println("CLASS & DIV : "+clss+grd);
tot=sc.nextInt();
System.out.println("ROLL NO. : "+rn);
per=tot*100/1000;
System.out.println("TOTAL MARKS: "+tot);
if(per>80) System.out.println("PERCENTAGE: "+per);
{ System.out.println("GRADE : "+grd);
grd='A'; System.out.println("REMARK : "+rem);
rem="Excellent"; }
} }
Section B
Ans11 → WAP to print following menu. System.out.println("Enter two numbers ");
104 1. Addition a=sc.nextInt();
2. Subtraction b=sc.nextInt();
3. Multiplication switch(choice)
4. Division {
5. Exit case 1:
Enter your choice __ res = a+b;
Enter two number ___ ____ System.out.println("Result is "+res); break;
Result is ___ case 2:
import java.util.*; res = a-b;
class MenuDriven System.out.println("Result is "+res); break;
{ case 3:
public static void main() res = a*b;
{ System.out.println("Result is "+res); break;
int choice,a,b, res; case 4:
res = a/b;
Scanner sc = new Scanner(System.in);
System.out.println("Result is "+res); break;
System.out.println("1. Addition");
case 5:
System.out.println("2. Subtraction");
System.exit(0);
System.out.println("3. Multiplication"); default:
System.out.println("4. Division"); System.out.println("Wrong choice ");
System.out.println("5. Exit"); }
System.out.println("Enter your choice __"); }
choice = sc.nextInt(); }
Section B
Ans14 → import java.util.*; else
105
class Bill {
{ amt = 100*4.50 + 200*5 + (200)*5.70 +(units-500)*6.50;
public static void main() }
{ amt=amt+100;
int units ;
double amt=0.0; System.out.println("amount to be paid by customer "+amt);
Scanner sc =new Scanner(System.in); }
System.out.println("Enter units consumed "); //sopln() }
units=sc.nextInt();
if(units<=100)
{
amt=units*4.50;
}
else if(units<=300)
{
amt=100*4.50 + (units-100)*5;
}
else if(units<=500)
{
amt = 100*4.50 + 200*5 + (units-300)*5.70;
}
Section B
Ans15 →import java.util.*; else if (sales >= 25001 && sales <= 35000 )
106 public class Salesman_Q5 {
{ public void main() comm=sales*20/100;
{ allw=sales*10/100;
double sales,comm, allw,T_income; }
Scanner sc=new Scanner(System.in); // here sc is a object else if (sales >= 35001 && sales <= 45000 )
of Scanner class {
System.out.println("Enter Sales:"); comm=sales*25/100;
sales=sc.nextDouble(); allw=sales*12/100;
if ( sales <= 5000 ) }
{ else
comm=sales*0/100; {
allw=sales*2/100; comm=sales*30/100;
} allw=sales*15/100;
else if ( sales >= 5001 && sales <= 15000 ) }
T_income=sales+comm+allw;
{
System.out.println("Sales " +sales) ;
comm=sales * 10/100;
System.out.println("Commission Amount "+comm);
allw=sales * 5/100;
System.out.println("Allowance "+allw);
} System.out.println("Total Income "+T_income);
else if ( sales>=15001 && sales <= 25000) }
{ }
comm=sales * 15/100;
allw=sales * 8/100;
}
Mixed Imp Questions related to intro of java, value & data type, operators if-else & switch
107
Section B loops
Using the switch statement, write a menu driven program:
108
i) To check and display whether a number input by the user is a composite number or not (A number is said
to be a composite, if it has one or more than one factors excluding 1 and the number itself).
Example: 4, 6, 8, 9…