0% found this document useful (0 votes)
107 views155 pages

100 Java MCQs for Class 9 ICSE

The document is a compilation of multiple-choice questions (MCQs), fill-in-the-blanks, and two-mark questions related to Java and Object-Oriented Programming (OOP) for Class 9 ICSE students. It covers fundamental concepts such as classes, objects, encapsulation, inheritance, and various Java keywords and operators. The content is designed to be exam-friendly and serves as a study guide for students preparing for their assessments.

Uploaded by

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

100 Java MCQs for Class 9 ICSE

The document is a compilation of multiple-choice questions (MCQs), fill-in-the-blanks, and two-mark questions related to Java and Object-Oriented Programming (OOP) for Class 9 ICSE students. It covers fundamental concepts such as classes, objects, encapsulation, inheritance, and various Java keywords and operators. The content is designed to be exam-friendly and serves as a study guide for students preparing for their assessments.

Uploaded by

supratimstars
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

“Code Beyond Limits.

”Java MasterBook”

Compiled by Amit Sir 9547442404


✅100 MCQ – Class 9 ICSE Java & OOP

(All options in one line, very simple, exam-friendly)

1. Java is a ______ language.


a) procedural b) object-oriented c) assembly d) machine
2. OOP stands for ______.
a) Object Order Programming b) Object-Oriented Programming c) Other Operating Program d)
Object Output Program
3. A class is a ______.
a) blueprint b) variable c) loop d) compiler
4. An object is an ______ of a class.
a) extension b) instance c) operator d) keyword
5. Encapsulation means ______.
a) linking programs b) wrapping data and methods c) only data hiding d) removing errors
6. Abstraction means ______.
a) showing details b) hiding details c) deleting details d) repeating details
7. Polymorphism means ______.
a) many meanings b) many operations c) many behaviors d) all of these
8. Inheritance means ______.
a) reusing code b) hiding data c) deleting values d) storing memory
9. Which keyword is used to define a class?
a) object b) class c) this d) main
10. new keyword is used to ______.
a) delete object b) create object c) rename object d) copy object
11. Java was developed by ______.
a) Microsoft b) Sun Microsystems c) Google d) IBM
12. Java code is compiled into ______.
a) bytecode b) machine code c) binary code d) source code
13. JVM stands for ______.
a) Java Virtual Machine b) Java Visual Model c) Java Visual Machine d) Java Version Model
14. JDK stands for ______.
a) Java Demo Kit b) Java Development Kit c) Java Data Kit d) Java Display Kit
15. JRE stands for ______.
a) Java Runtime Environment b) Java Running Editor c) Java Result Engine d) Java Root Environment
16. Which symbol ends a Java statement?
a) : b) ; c) , d) .
17. Which is NOT a primitive data type?
a) int b) char c) String d) boolean
18. char stores ______.
a) words b) letters c) sentences d) decimals
19. A variable is used to ______.
a) show output b) store data c) create loops d) run program
20. A fixed value in Java is called ______.
a) literal b) operator c) loop d) identifier
21. Which is a keyword?
a) total b) class c) sum d) avg
22. Which is NOT an operator?
a) + b) - c) = d) print
23. == is a ______ operator.
a) logical b) assignment c) relational d) increment
24. && is a ______ operator.
a) relational b) logical c) assignment d) unary
25. % operator gives ______.
a) quotient b) remainder c) power d) fraction
26. if statement is used for ______.
a) loops b) decision-making c) classes d) arrays
27. A loop is used to ______.
a) stop program b) repeat tasks c) reduce memory d) break code
28. for loop executes ______.
a) unknown times b) known number of times c) never d) only once
29. continue statement ______.
a) ends loop b) skips step c) starts program d) stops program
30. break statement ______.
a) stops loop b) doubles loop c) skips loop d) repeats loop
31. An array is a collection of ______.
a) files b) similar data types c) programs d) classes
32. Array index starts from ______.
a) 1 b) 2 c) 0 d) -1
33. String is a ______.
a) primitive type b) reference type c) operator d) keyword
34. A method is a ______.
a) variable b) function c) loop d) object
35. A constructor has the same name as ______.
a) method b) variable c) class d) package
36. Which keyword is used to access object members?
a) . b) : c) ; d) ,
37. main() is a ______.
a) object b) method c) variable d) class
38. [Link]() is used to ______.
a) take input b) print output c) make loops d) store data
39. Which operator is used for assignment?
a) == b) = c) === d) :–
40. A package is used to ______.
a) print output b) group classes c) store data d) control loops
41. Which is a logical operator?
a) > b) < c) && d) +
42. A reference variable stores ______.
a) value b) address of object c) loops d) methods
43. Which keyword creates a class object?
a) make b) build c) new d) object
44. Which is NOT an OOP principle?
a) inheritance b) parsing c) polymorphism d) abstraction
45. Java supports ______.
a) platform dependency b) platform independence c) only Windows d) no portability
46. Who is known as the father of Java?
a) Bill Gates b) James Gosling c) Guido Rossum d) Mark Zuckerburg
47. Java file extension is ______.
a) .txt b) .java c) .exe d) .jav
48. Compiled Java file extension is ______.
a) .txt b) .class c) .out d) .exe
49. Which function finds square root?
a) [Link]() b) [Link]() c) root() d) sqrt()
50. Which function finds power?
a) [Link]() b) power() c) pow() d) [Link]()
51. Which of these is a loop?
a) for b) if c) switch d) case
52. Which executes at least once?
a) for b) while c) do-while d) if
53. Java comments start with ______.
a) // b) \ c) /*** d) */
54. Multi-line comments begin with ______.
a) // b) /* c) /// d) #
55. A Boolean variable stores ______.
a) true/false b) numbers c) characters d) words
56. Which operator increases value by 1?
a) ++ b) + c) – d) +=
57. Arithmetic expressions follow ______.
a) left order b) BODMAS c) random order d) no rule
58. String concatenation uses ______.
a) – b) + c) * d) %
59. Which class is used for math functions?
a) Math b) String c) System d) Integer
60. Access modifiers control ______.
a) memory b) visibility c) speed d) colors
61. A blueprint of an object is ______.
a) array b) class c) loop d) variable
62. An object has ______.
a) size only b) state + behaviour c) behaviour only d) no property
63. this keyword refers to ______.
a) current class b) next class c) previous class d) old object
64. A method inside a class is called ______.
a) element b) member method c) module d) operator
65. A class can contain ______.
a) only data b) only methods c) both data & methods d) none
66. Which statement is true?
a) object = class b) class creates object c) class = object’s copy d) object creates class
67. Which is NOT a loop?
a) for b) while c) do-while d) where
68. Which operator checks not equal?
a) =! b) != c) <> d) ^=
69. Keywords are ______.
a) modifiable b) reserved words c) variables d) functions
70. Which data type stores decimals?
a) int b) double c) char d) boolean
71. Which data type stores true/false?
a) boolean b) int c) char d) double
72. A group of statements is called a ______.
a) block b) line c) symbol d) class
73. Loop which depends on condition is ______.
a) for b) while c) switch d) print
74. Parent class is called ______.
a) subclass b) superclass c) child class d) base class
75. A method that returns nothing uses ______.
a) return b) void c) null d) none
76. Which is a valid identifier?
a) 2rate b) rate2 c) rate-2 d) rate.2
77. A String is enclosed inside ______.
a) ‘ ’ b) “ ” c) { } d) [ ]
78. A character is enclosed in ______.
a) “ ” b) ‘ ’ c) [ ] d) { }
79. Which creates a comment?
a) & b) // c) %% d) ::
80. Which is a conditional operator?
a) ? : b) ++ c) % d) **
81. Which gives remainder?
a) / b) * c) % d) –
82. What is the base of all Java classes?
a) class b) Object c) System d) Math
83. Java is ______ typed.
a) loosely b) strongly c) weakly d) not
84. A block of code is enclosed in ______.
a) ( ) b) { } c) [ ] d) < >
85. Which loop checks condition first?
a) do-while b) while c) switch d) if
86. Index of first element in array?
a) 1 b) 0 c) -1 d) 10
87. Which is TRUE for constructors?
a) return type b) void c) no return type d) int
88. Which is NOT a valid access modifier?
a) public b) private c) protect d) protected
89. A class file contains ______.
a) bytecode b) machine code c) source code d) text
90. Which is a reference type?
a) int b) double c) String d) char
91. Java supports ______.
a) single inheritance b) multiple inheritance c) both d) none
92. The process of creating object is called ______.
a) objecting b) instantiation c) forming d) binding
93. A method header contains ______.
a) body b) signature c) result d) class
94. Which method finds maximum?
a) [Link]() b) [Link]() c) Max() d) greatest()
95. Java is ______.
a) compiled b) interpreted c) both compiled & interpreted d) neither
96. Which checks datatype compatibility?
a) static typing b) strong typing c) dynamic d) invalid typing
97. A class is written inside ______.
a) brackets b) curly braces c) square brackets d) angle brackets
98. Which creates a new line?
a) \n b) /n c) //n d) new line
99. Which is NOT a Java feature?
a) secure b) portable c) slow d) platform-dependent
100. Java code runs on ______.
a) JVM b) BIOS c) CPU only d) HTML
✅100 Fill in the Blanks – Class 9 ICSE Java & OOP Concepts
1. Java programs are written inside a ______.
2. An object contains state and ______.
3. A class is also known as a ______ of objects.
4. The process of hiding internal details is called ______.
5. A method inside a class is also called a ______ method.
6. The keyword used to define a class is ______.
7. Data members of a class are also called ______.
8. Java source code is saved with the extension ______.
9. Bytecode of Java is stored in ______ files.
10. The main() method must be declared as ______.
11. The keyword used to create an object is ______.
12. The dot (.) operator is used to access ______ of a class.
13. The process of creating an object is called ______.
14. The special method used to initialize an object is called a ______.
15. A constructor has the same name as the ______.
16. A method that does not return anything uses the keyword ______.
17. Java is a ______ level language.
18. Java supports ______ independence.
19. Every class in Java is part of a ______.
20. An interface provides ______% abstraction.
21. Java was originally developed by ______ Gosling.
22. The full form of OOP is ______ Oriented Programming.
23. Java programs always start execution from the ______ method.
24. Encapsulation combines data and ______.
25. The basic unit of data in Java is called a ______.
26. The data type that stores whole numbers is ______.
27. The data type used for true/false values is ______.
28. Strings are enclosed in ______ quotes.
29. Characters are enclosed in ______ quotes.
30. The assignment operator in Java is ______.
31. The operator used to add two numbers is ______.
32. The condition in an if statement must be a ______ expression.
33. The operator used to compare two values for equality is ______.
34. The operator that means NOT equal is ______.
35. && and || are ______ operators.
36. The operator used for remainder is ______.
37. A loop repeats a block of ______.
38. The loop that checks condition first is ______ loop.
39. The loop that executes at least once is ______ loop.
40. The keyword used to exit a loop immediately is ______.
41. The keyword used to skip the current loop iteration is ______.
42. A collection of similar data items is called an ______.
43. Array index starts from ______.
44. The Math class belongs to the ______ package.
45. [Link]() is used to calculate ______.
46. [Link]() is used to find the ______ root.
47. The length of an array is given by the variable ______.
48. A sequence of characters is called a ______.
49. Java is both compiled and ______.
50. Java compiler is called ______.
51. Java compiler converts source code into ______.
52. Variables inside a class but outside methods are called ______ variables.
53. Variables declared inside methods are called ______ variables.
54. The = operator is an ______ operator.
55. The == operator is a ______ operator.
56. The keyword used to inherit a class is ______.
57. The child class is also called a ______ class.
58. The parent class is also called a ______ class.
59. Multiple classes in Java can be grouped into a ______.
60. Java follows the rule: write once, ______ anywhere.
61. The smallest unit of a Java program is a ______.
62. A valid Java identifier cannot start with a ______.
63. Before using a variable, it must be ______.
64. A block of code is enclosed within ______ braces.
65. The ++ operator increases value by ______.
66. The -- operator decreases value by ______.
67. In Java, String is a(n) ______ data type.
68. A method header ends with ______ parentheses.
69. The keyword return is used to ______ a value.
70. Java supports ______ inheritance only.
71. The keyword used to define a constant is ______.
72. Comments starting with // are ______ line comments.
73. Multi-line comments begin with ______.
74. The statement [Link]() prints output and moves to ______ line.
75. To store decimal values, we use the data type ______.
76. A class combines data and ______.
77. Java is known for its high ______ security.
78. Java programs are executed inside the ______.
79. The keyword true is of ______ data type.
80. A Boolean variable stores ______ values.
81. Java supports ______ level of abstraction.
82. An operator that combines two conditions is a ______ operator.
83. The continue statement sends control to the ______ of loop.
84. The break statement sends control ______ the loop.
85. A package helps in ______ code.
86. The new operator allocates ______ for objects.
87. The dot operator is also called the ______ operator.
88. Java is free from ______ errors due to strict typing.
89. String values are ______, meaning they cannot change.
90. An object is created from a ______.
91. A class that cannot be instantiated directly is called an ______ class.
92. The process of linking a method call to its body is called ______ binding.
93. A method that returns a value must specify a ______ type.
94. A Java project contains one or more ______.
95. A method that accepts parameters is called a ______ method.
96. A method with the same name but different parameters uses ______ overloading.
97. A class can contain more than one ______.
98. Keywords cannot be used as ______.
99. Memory for primitive types is stored in the ______.
100. Memory for objects is stored in the ______.
✅25 Two-Marks Questions and Answers (Class 9 – OOP in Java)
1. What is Object-Oriented Programming?
Answer:
Object-Oriented Programming (OOP) is a programming approach that uses objects and classes to
design programs. It focuses on real-world entities and provides features like abstraction,
polymorphism, inheritance, and encapsulation.
2. Define a class with an example.
Answer:
A class is a blueprint or template for creating objects.
Example:
class Student {
String name;
int age;
}
3. What is an object? Give an example.
Answer:
An object is an instance of a class containing data and methods.
Example:
Student s1 = new Student();
4. What is data abstraction?
Answer:
Data abstraction means showing only essential details and hiding unnecessary information.
Example: A car driver uses a steering wheel but doesn't know the internal mechanism.
5. Define encapsulation.
Answer:
Encapsulation is the process of wrapping data and methods into a single unit (class) and protecting
data using access modifiers like private.
6. What is polymorphism?
Answer:
Polymorphism means “many forms”. It allows the same function to behave differently based on
input or object.

7. What is inheritance?
Answer:
Inheritance allows one class (child) to acquire the properties of another class (parent), promoting
code reusability.
8. What is a constructor?
Answer:
A constructor is a special method used to initialize objects. It has the same name as the class and no
return type.
9. What is the difference between a constructor and a method?
Answer:
A constructor initializes an object and has no return type; a method performs tasks and may return
values.
10. What is method overloading?
Answer:
Method overloading occurs when multiple methods in the same class have the same name but
different parameters.
11. What do you mean by access specifiers?
Answer:
Access specifiers (public, private, protected) control the visibility of variables and methods in Java.
12. What is this keyword in Java?
Answer:
this refers to the current object of the class, used to differentiate between instance variables and
parameters.
13. What is the purpose of the new keyword?
Answer:
new is used to create objects in Java and allocate memory.
14. Define instance variables.
Answer:
Instance variables are variables declared inside a class but outside any method. They store object-
specific data.
15. What are member functions?
Answer:
Member functions (methods) are functions declared inside a class to perform actions on objects.
16. What is the use of the dot (.) operator?
Answer:
The dot operator is used to access members (variables/methods) of an object.
Example: [Link]();
17. Define static members.
Answer:
Static members belong to the class, not objects. They can be accessed without creating an object.
18. What is the difference between object and class?
Answer:
A class is a template; an object is an instance created using the class.
19. What is a parameterized constructor?
Answer:
A constructor that accepts parameters to initialize object values.
Example:
Student(String n, int a)
20. What is method overriding?
Answer:
Method overriding occurs when a subclass provides a new implementation for a method already
defined in the parent class.
21. What is an attribute in OOP?
Answer:
Attributes are the data members (variables) that store the properties of an object.
22. What is an operation in OOP?
Answer:
Operations are the functions or methods that define the behavior of an object.
23. What is an object reference?
Answer:
An object reference is a variable that stores the address of the object in memory.
24. What are the advantages of OOP?
Answer:
Code reusability
Easy maintenance
Data security
Real-world modeling
25. Define blueprint approach in OOP.
Answer:
OOP treats classes as blueprints that describe properties and behaviors of objects to be created
later.
✅100 MCQs – Values, Data Types & Operators in Java
(Options on Next Line — No Blank Lines)

Q1. Java is a ___ typed language.


A. Static B. Dynamic C. Weak D. Loose
Q2. Which of these is not a primitive data type?
A. int B. boolean C. String D. char
Q3. Size of int in Java is ___.
A. 2 bytes B. 4 bytes C. 8 bytes D. 1 byte
Q4. Default value of boolean is ___.
A. true B. false C. 0 D. undefined
Q5. Which data type stores decimal values?
A. int B. double C. char D. boolean
Q6. Which operator is used for multiplication?
A. * B. / C. % D. +
Q7. Which data type is smallest?
A. byte B. short C. int D. long
Q8. Range of byte is ___.
A. -128 to 127 B. -256 to 255 C. -64 to 63 D. 0 to 255
Q9. Which operator finds remainder?
A. % B. / C. * D. +
Q10. Which keyword declares a constant?
A. const B. final C. static D. constant
Q11. Which data type stores a single character?
A. char B. String C. int D. byte
Q12. char in Java uses ___.
A. ASCII B. Unicode C. Hexadecimal D. Binary
Q13. Which operator increases value by 1?
A. ++ B. -- C. + D. *
Q14. Which is NOT an arithmetic operator?
A. + B. - C. & D. %
Q15. Which data type stores true/false?
A. boolean B. byte C. int D. char
Q16. What is the size of double?
A. 4 bytes B. 8 bytes C. 2 bytes D. 1 byte
Q17. Which operator has highest precedence?
A. * B. + C. = D. ==
Q18. Which is NOT a logical operator?
A. && B. || C. ! D. %
Q19. float literal must end with ___.
A. F/f B. D/d C. L/l D. None
Q20. Which operator is assignment operator?
A. = B. == C. != D. equals
Q21. Which data type is used for long integers?
A. int B. long C. short D. byte
Q22. Which operator compares two values?
A. == B. = C. += D. *
Q23. Java uses ___ for true/false.
A. boolean B. 0/1 C. char D. int
Q24. Which stores larger values?
A. double B. float C. byte D. char
Q25. Which operator checks inequality?
A. != B. == C. = D. >=
Q26. Which data type stores text?
A. String B. char C. int D. byte
Q27. Which operator is unary?
A. ++ B. + C. - D. *
Q28. Which operator performs logical AND?
A. && B. & C. | D. !
Q29. Which operator performs logical OR?
A. || B. & C. == D. =
Q30. Result of 10 % 3 is ___.
A. 1 B. 3 C. 0 D. 10
Q31. Which represents a character literal?
A. 'A' B. "A" C. A D. (A)
Q32. Which is larger?
A. long B. int C. short D. byte
Q33. 5 / 2 in integer division gives ___.
A. 2 B. 2.5 C. 3 D. 1
Q34. Which data type is 16-bit?
A. short B. char C. int D. byte
Q35. Which operator is NOT relational?
A. % B. > C. < D. >=
Q36. Which operator is used for NOT?
A. ! B. & C. && D. %
Q37. Which keyword is used for decimal numbers?
A. double B. int C. boolean D. char
Q38. Default value of int is ___.
A. 0 B. null C. undefined D. 1
Q39. Which operator performs division?
A. / B. % C. * D. -
Q40. Which stores bigger values?
A. long B. int C. short D. byte
Q41. Which operator is ternary?
A. ?: B. & C. || D. !=
Q42. Which is not a valid identifier?
A. 1num B. _abc C. var1 D. total
Q43. Which is NOT primitive?
A. String B. float C. int D. boolean
Q44. Which operator checks greater?
A. > B. < C. == D. =
Q45. Which operator is equality operator?
A. == B. = C. != D. <>
Q46. Size of boolean is ___.
A. JVM dependent B. 1 bit C. 8 bytes D. 4 bytes
Q47. 10 + 20 + "Java" gives ___.
A. 30Java B.Java30 C.1020Java [Link]
Q48. "Java" + 10 gives ___.
A. Java10 B. 10Java C. Error D. 20
Q49. Which operator decreases value?
A. -- B. ++ C. * D. -
Q50. Which is NOT assignment?
A. == B. = C. += D. -=
Q51. Which literal is invalid?
A. 10FZ B. 10 C. 010 D. 0x1F
Q52. char uses __ bytes.
A. 2 B. 1 C. 4 D. 8
Q53. Which operator joins strings?
A. + B. * C. & D. %
Q54. 5 % 5 gives ___.
A. 0 B. 1 C. 5 D. Error
Q55. Which is a logical operator?
A. && B. % C. * D. +
Q56. Which is a relational operator?
A. > B. & C. && D. *
Q57. Which converts int to double automatically?
A. Type promotion B. Casting C. Deletion D. None
Q58. Which stores whole numbers?
A. int B. float C. double D. boolean
Q59. Single-line comment uses ___.
A. // B. /* C. / D. #
Q60. Multi-line comment starts with ___.
A. / B. // C. / D. #
Q61. Which operator is bitwise AND?
A. & B. && C. | D. ^
Q62. Range of short is ___.
A. -32768 to 32767 B. -128 to 127 C. 0–65535 D. 0–255
Q63. Which is bitwise OR?
A. | B. || C. & D. !
Q64. Which converts double to int?
A. Casting B. Promotion C. AND D. Shifting
Q65. Which is valid float literal?
A. 12.5f B. 12.5D C. 12.5L D. 12,5
Q66. Which datatype is used for small integers?
A. byte B. long C. double D. char
Q67. Which operator shifts bits left?
A. << B. >> C. >>> D. ^
Q68. Which operator shifts bits right?
A. >> B. << C. += D. ==
Q69. Which operator is XOR?
A. ^ B. & C. && D. |
Q70. Which operator is compound assignment?
A. += B. = C. == D. !=
Q71. Which operator concatenates two strings?
A. + B. & C. % D. *
Q72. Which operator has lowest precedence?
A. = B. * C. ++ D. %
Q73. Which is NOT a keyword?
A. main B. int C. long D. double
Q74. Size of long is ___.
A. 8 bytes B. 4 bytes C. 2 bytes D. 1 byte
Q75. Which gives true?
A. 5 < 10 B. 10 < 5 C. 5 == 6 D. 10 != 10
Q76. Which gives false?
A. 8 < 2 B. 10 > 5 C. 5 == 5 D. 5 >= 1
Q77. Which operator is used to combine conditions?
A. && B. = C. * D. /
Q78. Which is NOT unary?
A. * B. ++ C. -- D. +
Q79. Which is valid?
A. boolean x = true; B. boolean x = 1; C. boolean x = "true"; D. boolean x = yes;
Q80. Which operator performs modulo?
A. % B. / C. - D. *
Q81. Which gives decimal answer?
A. 5/2.0 B. 5/2 C. 5%2 D. 52
Q82. Which is long literal?
A. 10L B. 10F C. 10.5 D. 'A'
Q83. String literal is inside ___.
A. " " B. ' ' C. ( ) D. { }
Q84. Which is implicit conversion?
A. int → double B. double → int C. char → int D. boolean → int
Q85. Which is explicit casting?
A. double → int B. int → long C. int → double D. byte → short
Q86. 10 == 10 gives ___.
A. true B. false C. 0 D. Error
Q87. 10 != 5 gives ___.
A. true B. false C. Error D. 0
Q88. Which is NOT numeric?
A. boolean B. int C. double D. float
Q89. Which operator assigns value?
A. = B. == C. != D. >=
Q90. Which one is integer literal?
A. 100 B. 10.5 C. 'A' D. "100"
Q91. Which one is character literal?
A. 'b' B. "b" C. (b) D. b
Q92. Which satisfies Unicode standard?
A. char B. int C. float D. byte
Q93. Which is a boolean operator?
A. && B. % C. * D. +
Q94. Which is NOT a valid char literal?
A. 'AB' B. 'A' C. '3' D. '!'
Q95. Which gives true?
A. !false B. !true C. 5==6 D. 10<5
Q96. Which is postfix operator?
A. i++ B. ++i C. * D. -
Q97. Which is prefix operator?
A. ++i B. i++ C. - D. *
Q98. Which is narrowing conversion?
A. int → byte B. byte → int C. int → long D. float → double
Q99. Which is widening conversion?
A. byte → int B. int → byte C. double → float D. long → short
Q100. Which operator evaluates first?
A. * B. + C. = D. &
✅100 Fill in the Blanks (Java – Values,
Data Types, Operators)
1. The keyword used to declare a variable in Java is __________.
2. A variable that holds whole numbers is of type __________.
3. The data type used to store a single character is __________.
4. Floating-point values with double precision are stored using __________.
5. The data type with the largest range among primitives is __________.
6. The smallest integer data type in Java is __________.
7. A boolean variable can store only __________ or false.
8. The operator used for addition in Java is __________.
9. The operator used to check equality is __________.
10. The % operator gives the __________ of a division.
11. The operator used for subtraction is __________.
12. The operator used for multiplication is __________.
13. The operator for integer division is __________.
14. The operator ++ is called the __________ operator.
15. The operator -- is called the __________ operator.
16. The operator used for assignment is __________.
17. The logical AND operator in Java is __________.
18. The logical OR operator in Java is __________.
19. The logical NOT operator in Java is __________.
20. The data type char stores values inside __________ quotes.
21. The data type String stores values inside __________ quotes.
22. The size of an int variable is __________ bytes.
23. The size of a byte variable is __________ bytes.
24. The size of a short variable is __________ bytes.
25. The size of a long variable is __________ bytes.
26. The size of a float variable is __________ bytes.
27. The size of a double variable is __________ bytes.
28. The size of a char variable is __________ bytes.
29. A literal value written directly in the program is called a __________.
30. The expression 10 / 4 gives the value __________.
31. The expression 10 % 4 gives the value __________.
32. The value of true && false is __________.
33. The value of true || false is __________.
34. The value of !true is __________.
35. Java does not allow implicit type conversion from double to __________.
36. A value that cannot be changed is declared using the keyword __________.
37. The combination of variable name, type, and value is called a __________.
38. The operator used to compare two values is __________.
39. The result of 5 + 3 * 2 is __________.
40. A variable name is also known as an __________.
41. The data type used for decimal values with single precision is __________.
42. Character values are internally stored using __________ code.
43. The range of byte is __________ to __________.
44. The range of short is __________ to __________.
45. A variable must be __________ before use.
46. Java is a __________ typed language.
47. In Java, data types are divided into primitive and __________.
48. A group of characters is stored using the data type __________.
49. The operator used to compare two values for inequality is __________.
50. The operator += is known as __________ assignment operator.
51. The operator *= is known as __________ assignment operator.
52. The operator /= is known as __________ assignment operator.
53. The operator %= is known as __________ assignment operator.
54. The expression (5 > 3) evaluates to __________.
55. The expression (5 < 3) evaluates to __________.
56. The expression (10 == 10) evaluates to __________.
57. The expression (10 != 5) evaluates to __________.
58. A variable declared but not initialized contains __________ value.
59. In Java, division between two integers gives an __________ result.
60. 7 % 2 results in __________.
61. 8 % 4 results in __________.
62. 9 % 3 results in __________.
63. The operator used for exponent in Java is __________ (Trick: Java has none).
64. Java evaluates expressions from __________ to right.
65. The type of 10.5 by default is __________.
66. The type of 10 by default is __________.
67. The operator used to join two strings is __________.
68. The value of 'A' + 1 is __________.
69. The ASCII value of 'A' is __________.
70. The Unicode system uses __________ bits.
71. The prefix increment operator adds __________ before evaluation.
72. The postfix increment operator adds __________ after evaluation.
73. The minimum value of int is __________.
74. The maximum value of int is __________.
75. The result of 4 * 2 + 6 is __________.
76. The result of (4 * (2 + 6)) is __________.
77. The operator with highest precedence is __________.
78. The operator with lowest precedence is __________.
79. The value of true || true is __________.
80. The value of false && true is __________.
81. The boolean operator that stops evaluation when result is known is __________.
82. The + operator works on strings for __________.
83. Java keywords cannot be used as __________ names.
84. A constant value written directly is known as __________.
85. A variable of type float must end with the letter __________.
86. A variable of type long may end with the letter __________.
87. Characters in Java use __________ encoding.
88. The range of char is from __________ to __________.
89. The number of primitive data types in Java is __________.
90. The result of 3 + 4 * 2 is __________.
91. The result of (3 + 4) * 2 is __________.
92. The operator used for relational comparison is __________.
93. The operator used to test two conditions is __________.
94. The operator used to invert a boolean value is __________.
95. The operator used to compare memory addresses in objects is __________.
96. The default value of int is __________.
97. The default value of double is __________.
98. The default value of boolean is __________.
99. The default value of char is __________.
100. The smallest positive float value is represented by __________.
✅50 Questions (2 Marks Each) with Answers
Topic: Java – Values, Data Types, Operators

1. What is a variable in Java?

Ans: A variable is a named memory location used to store a value that can change during
program execution.
2. What is a data type?

Ans: A data type specifies the type of value a variable can store, such as int, char, double,
etc.
3. What is the difference between int and double?

Ans: int stores whole numbers; double stores decimal/floating-point numbers.


4. What is a literal?

Ans: A literal is a fixed value written directly in the program like 10, 'A', 3.5.
5. What is a character constant?

Ans: A character constant is a single character enclosed in single quotes, e.g., 'A'.
6. What is a string constant?

Ans: A string constant is a sequence of characters enclosed in double quotes, e.g., "Hello".
7. What is the purpose of the boolean data type?

Ans: It stores logical values true or false.


8. What is the range of byte in Java?

Ans: –128 to 127.


9. What is the size of the int data type?

Ans: 4 bytes.
10. Why is Java called a strongly typed language?

Ans: Because every variable must be declared with a specific data type before use.
11. What does the % operator do?

Ans: It returns the remainder of a division operation.


12. What is the difference between = and == ?

Ans: = is assignment; == is comparison for equality.


13. What is the use of the increment operator?

Ans: It increases the value of a variable by 1.


14. What is the difference between prefix and postfix increment?

Ans: Prefix (++a) updates first, postfix (a++) updates after using the value.
15. What is an expression?

Ans: A combination of variables, operators, and values that produces a result.


16. What is a constant in Java?

Ans: A constant is a value that cannot change, declared using the keyword final.
17. What is type casting?

Ans: Converting one data type into another manually, e.g., (int) 3.5.
18. What is implicit type conversion?

Ans: Automatic conversion done by Java from smaller to larger types, e.g., int to double.
19. What is the Unicode system?

Ans: A character encoding standard used by Java to represent characters.


20. Define operator.

Ans: An operator is a symbol that performs an operation on operands, e.g., +, -, *.


21. What are relational operators?

Ans: Operators that compare values, e.g., >, <, >=, <=, ==, !=.
22. What are logical operators?

Ans: Operators used to combine conditions: &&, ||, !.


23. What is the result of true && false?

Ans: false.
24. What is short-circuit evaluation?

Ans: Java stops evaluating further conditions if the result is already known.
25. Give an example of a valid identifier.

Ans: studentName, totalMarks, _count.


26. Give an example of an invalid identifier.

Ans: 2name, total marks, class (because it's a keyword).


27. What is precedence of operators?

Ans: The order in which operators are evaluated in an expression.


28. What is associativity?

Ans: It defines the direction (left-to-right or right-to-left) of evaluation.


29. What is the purpose of char data type?

Ans: It stores a single Unicode character.


30. What is the difference between float and double?

Ans: float is 4 bytes (single precision); double is 8 bytes (double precision).


31. What is a compound assignment operator?

Ans: Operators that combine arithmetic with assignment, e.g., +=, -=.
32. What is the use of the + operator with strings?

Ans: It is used for string concatenation (joining strings).


33. What is a boolean expression?

Ans: An expression that results in true or false.


34. What is the role of the assignment operator?

Ans: It assigns a value to a variable.


35. What is the purpose of parentheses in expressions?

Ans: To change or control the order of evaluation.


36. What happens when an integer is divided by another integer in Java?

Ans: The result is an integer (fractional part is discarded).


37. What is a mixed expression?

Ans: An expression with different data types, like int + double.


38. What is the default value of int?

Ans: 0.
39. What is the default value of boolean?

Ans: false.
40. What is the default value of char?

Ans: '\u0000' (null character).


41. What does the != operator check?

Ans: It checks if two values are not equal.


42. What is the meaning of >= operator?

Ans: Greater than or equal to.


43. Why are data types important in Java?

Ans: They determine the type and size of data stored in variables.
44. What is the result of 5 + 2 * 3?

Ans: 11 (multiplication first).


45. What is the result of (5 + 2) * 3?

Ans: 21 (parentheses first).


46. What happens during overflow in integer operations?

Ans: Value wraps around within its range, giving incorrect results.
47. Why is float written with 'f' at the end?

Ans: To tell Java that the literal is of type float, not double.
48. What is a primitive data type?

Ans: Basic built-in data types like int, byte, float, boolean.
49. What is a non-primitive data type?

Ans: User-defined or complex data types like String, arrays, classes.


50. What is the result of true || false?

Ans: true.
📘 QUESTION PAPER
Subject: Computer Applications (Java)

Topic: OOP Concepts, Values & Data Types

Total Marks: 50

Time: 1½ Hours

SECTION A – MCQs (10 × 1 = 10 Marks)

Choose the correct option.

1. OOP stands for


D. None C. Ordered Object Program B. Object Online Program A. Object
Oriented Programming
2. Which one is not a primitive data type?
D. double C. String B. boolean A. int
3. A group of objects having similar properties is called a
D. Module C. Package B. Class A. Method
4. A single character is stored using
D. String C. byte B. char A. int
5. The operator used for equality comparison is
D. C. != B. == A. = >
6. The keyword used to declare a constant is
D. var C. const B. final A. static
7. Which principle binds data and methods together?
D. Abstraction C. Inheritance B. Encapsulation A. Polymorphism
8. 10 % 3 gives
D. 0 C. 10 B. 1 A. 3
9. Which datatype can store decimal values?
D. boolean C. char B. double A. int
10. The size of byte is
D. 8 bytes C. 4 bytes B. 2 bytes A. 1 byte

SECTION B – Fill in the Blanks (10 × 1 = 10 Marks)

11. Java is a __________ typed programming language.


12. A __________ is a blueprint of objects.
13. The process of wrapping data and methods is called __________.
14. The smallest integer data type is __________.
15. The __________ operator gives the remainder.
16. A value written directly in the program is called a __________.
17. A __________ stores true or false.
18. A String value is enclosed within __________ quotes.
19. The operator && is known as __________ AND.
20. A variable must be __________ before use.
SECTION C – Short Answer Questions (10 × 2 = 20 Marks)

Answer the following in 2–3 sentences.

21. What is an object? Give an example.


22. Define class with an example from daily life.
23. What is abstraction?
24. What is a primitive data type? Name any four.
25. State the difference between float and double.
26. What is the role of the new keyword in Java?
27. Explain the difference between = and == operators.
28. What is a boolean expression?
29. What is type casting? Give an example.
30. Explain the concept of encapsulation.

SECTION D – Long Answer Questions (2 × 5 = 10 Marks)

Answer any two.

31. Explain the four major OOP principles with examples.

 Encapsulation
 Inheritance
 Polymorphism
 Abstraction

32. Describe all primitive data types in Java along with their size and example values.
33. Explain arithmetic, relational and logical operators with suitable Java examples.

📘 QUESTION PAPER – SET 2 (MEDIUM


LEVEL)
Subject: Computer Applications (Java)

Total Marks: 50

Time: 1½ Hours

SECTION A – MCQs (10 × 1 = 10 Marks)

Choose the correct option.

1. Which feature of OOP allows creating new classes from existing ones?
D. Encapsulation C. Polymorphism B. Inheritance A. Abstraction
2. Which of the following is NOT an OOP concept?
D. Inheritance C. Object B. Looping A. Class
3. Which operator has the highest precedence?
D. C. == B. * A. + &&
4. The default value of a boolean variable is
D. null C. 0 B. false A. true
5. Which data type is used for 16-bit Unicode characters?
D. short C. char B. byte A. int
6. The process of hiding internal details and showing only necessary features is
D. Class C. Abstraction B. Polymorphism A. Encapsulation
7. Which operator checks if two values are NOT equal?
C. B. != A. == >D. = &&
8. The range of short data type is
D. –2^31 to 2^31–1 C. 0 to 65535 B. –32,768 to 32,767 A. –128 to 127
9. The literal for float must end with
D. b C. c B. d A. f
10. The result of 15 / 4 in Java is
D. 0.75 C. 4 B. 3 A. 3.75

SECTION B – Fill in the Blanks (10 × 1 = 10 Marks)

11. The binding of data with functions is called __________.


12. The new keyword is used to create an __________.
13. The __________ operator is used to concatenate two strings.
14. A collection of similar objects is known as a __________.
15. The __________ operator performs logical OR.
16. The size of long data type is __________ bytes.
17. A class defines both data members and __________.
18. The process of converting one data type into another is __________.
19. The operator with least precedence is __________.
20. A sequence of characters enclosed in double quotes is a __________.

SECTION C – Short Answer Questions (10 × 2 = 20 Marks)

Answer the following in 3–4 sentences.

21. What do you understand by Polymorphism? Give one real-world example.


22. Define inheritance. How is it useful?
23. What is the difference between primitive and non-primitive data types?
24. What is an identifier? Give two rules for naming identifiers.
25. Explain logical operators with examples.
26. What is the significance of Unicode in Java?
27. Define implicit type conversion with an example.
28. Write the difference between char and String.
29. What is the purpose of the modulus operator? Provide one example.
30. How does encapsulation increase security in programming?

SECTION D – Long Answer Questions (2 × 5 = 10 Marks)

Answer any TWO.

31. Explain the concept of a class and an object with two examples each (one real-life,
one Java-based).
32. Describe arithmetic, relational, and logical operators in Java with two examples of
each.
33. Explain in detail the advantages of OOP over procedural programming. Write at least
five points with explanations.

📘 QUESTION PAPER – SET 3 (HARD


LEVEL)
Subject: Computer Applications (Java)

Total Marks: 50

Time: 1½ Hours

SECTION A – MCQs (10 × 1 = 10 Marks)


Choose the correct answer.

1. Which OOP concept allows different objects to respond differently to the same
message?
D. Inheritance C. Abstraction B. Polymorphism A. Encapsulation
2. Which of the following is not a valid Java literal?
D. 0x2A C. "Hello" B. 'AB' A. 12.5f
3. Which operator is evaluated first in the expression: 4 + 5 * 2 >= 10 && true?
C. B. * A. + >D. = &&
4. The process where an object takes properties of another object is
D. Inheritance C. Encapsulation B. Abstraction A. Polymorphism
5. Which casting may lead to data loss?
D. Automatic C. Implicit B. Narrowing A. Widening
6. The default value of an uninitialized object reference is
D. undefined C. false B. null A. 0
7. The valid range of char in Java is
D. –128 to 127 C. 0 to 65535 B. 0 to 255 A. 0 to 127
8. Which feature of OOP enables a programmer to reuse existing code?
D. Encapsulation C. Polymorphism B. Abstraction A. Inheritance
9. Which operator results in a boolean output?
B. A. + &&D. % C. *
10. The value of expression (true || false) && (!false) is
D. 1 C. 0 B. false A. true

SECTION B – Fill in the Blanks (10 × 1 = 10


Marks)
11. The ability of a class to exist in multiple forms is known as __________.
12. The __________ keyword is used for creating objects dynamically.
13. The process of combining data and methods into a single unit is __________.
14. The __________ operator checks if two references point to different objects.
15. The size of double data type is __________ bytes.
16. __________ conversion occurs automatically when a smaller type is converted to a
larger type.
17. The logical NOT operator is represented by __________.
18. The __________ principle ensures unnecessary details are hidden from the user.
19. The __________ operator has the highest precedence among arithmetic operators.
20. In Java, every char is internally stored using the __________ encoding system.

SECTION C – Short Answer Questions (10 ×


2 = 20 Marks)
Answer the following in 3–4 sentences.

21. Explain method overloading and give one suitable example.


22. Describe the significance of constructors in object creation.
23. What are escape sequences? Give two examples.
24. Explain the difference between widening and narrowing conversions.
25. What is an abstract view of an object? Explain with an example.
26. Why does Java store characters using Unicode instead of ASCII?
27. Explain with example how precedence affects the evaluation of an expression.
28. What is a reference variable? How is it different from a primitive variable?
29. Explain the difference between immutable and mutable objects.
30. Differentiate between instance members and class (static) members.

SECTION D – Long Answer Questions (2 × 5


= 10 Marks)
Answer any TWO.

31. Discuss in detail how encapsulation, abstraction, inheritance, and polymorphism


together make Java a powerful OOP language. Provide examples for each concept.
32. Explain the significance of values, literals, variables, data types, and operators in Java
with suitable examples.

 Define each term clearly


 Provide short code examples
 Explain their roles in expression building

33. Describe the evaluation of the following expression step by step. Explain operator
precedence and associativity used at each stage:
int result = 12 + 4 * 3 - 10 / 2 + (5 % 2) * 4;

Also calculate the final result.


✅100 HARD OUTPUT QUESTIONS (With
Assigned Variables + Expression Only)
1–20 Basic + Precedence + Mixed Types

1. int a = 12, b = 5, c = 3; a + b * c
2. int a = 9, b = 4, c = 2; a - b + c * 5
3. int a = 20, b = 6; a / b + a % b
4. int a = 7, b = 3, c = 4; a * b - c / b
5. int a = 15, b = 5, c = 2; a / b * c + b
6. int a = 50, b = 8; a % b * 3
7. int a = 18, b = 7, c = 2; a - b * c + b
8. int a = 11, b = 3; a / b + b / a
9. int a = 100, b = 9; a / (b - 1)
10. int a = 28, b = 4, c = 6; a / b + c % b
11. double x = 5.5, y = 2.0; x + y * 3
12. double x = 9.2, y = 3.1; x / y + x
13. double x = 14.0, y = 4.0; x % y + y
14. double x = 7.8; int a = 3; x * a + x / a
15. float f = 5.5f; int a = 2; f * a + a
16. int a = 5, b = 2; double x = 4.5; a + b * x
17. int a = 6; double x = 2.5; a / x + x / a
18. double x = 8.5, y = 1.5; (int)x + (int)y * 2
19. int a = 20; double x = 3.2; (int)(a / x)
20. int a = 7, b = 3; (double)a / b

21–40 Increment / Decrement

21. int a = 10, b = 5; a++ + b++


22. int a = 12, b = 3; ++a + b--
23. int a = 9, b = 4, c = 2; a++ + --b * c
24. int a = 7, b = 6; --a + b++
25. int a = 11, b = 3, c = 5; a-- * ++b + c
26. int a = 15, b = 4; a++ * b--
27. int a = 8, b = 3; --a * --b
28. int a = 5, b = 9; a++ + ++b + b--
29. int a = 6, b = 2, c = 4; a-- + b++ + --c
30. int a = 20, b = 7; a-- - --b
31. int a = 13, b = 6; ++a - b--
32. int a = 17, b = 2, c = 3; ++a + c-- * b
33. int a = 4, b = 5; --a + --b
34. int a = 10, b = 2, c = 8; a++ * c-- - b++
35. int a = 6, b = 3; a++ + a++ + b++
36. int a = 9, b = 4; --a + b-- + a
37. int a = 12, b = 3, c = 2; c++ * --a + b
38. int a = 8, b = 5; ++a - ++b + a--
39. int a = 14, b = 4; a-- + --a + b++
40. int a = 10, b = 6, c = 3; a-- * b-- / ++c
41–60 Char + String + ASCII

41. char p = 'A', q = 'C'; p + q


42. char p = 'a', q = 'z'; q - p
43. char p = 'D'; p + 5
44. char p = 'X'; p - 2
45. char p = 'A'; int a = 3; p + a
46. char p = 'c'; char q = 'a'; p - q
47. char p = 'A'; (char)(p + 3)
48. char p = 'Z'; (char)(p - 5)
49. String s = "Hi"; s + 5 + 5
50. String s = "A"; int a = 7; s + a + "B"
51. char p = 'A'; double x = 3.5; p + x
52. char p = 'K'; int a = 8; (char)(p + a)
53. char p = 'a'; int a = 25; (char)(p + a)
54. char p = 'F'; int a = 3, b = 1; p + a - b
55. String s = "Hi"; int a = 3; s + (a + 2)
56. String s = "Code"; int a = 5; s + a * 2
57. char p = 'M'; p + 'A'
58. char p = 'd'; (int)p
59. char p = 65; p + 5
60. String s = "A"; char p = 'B'; s + p

61–80 Bitwise Operators

61. int a = 12, b = 5; a & b


62. int a = 9, b = 3; a | b
63. int a = 7, b = 2; a ^ b
64. int a = 14; a << 1
65. int a = 20; a >> 2
66. int a = 5, b = 3; (a & b) + (a | b)
67. int a = 8, b = 4; a ^ b ^ 2
68. int a = 6; a << 2
69. int a = 32; a >> 3
70. int a = 11, b = 6; a & b | a
71. int a = 15, b = 7; (a & b) ^ 3
72. int a = 9; (~a)
73. int a = 17, b = 3; a & (b << 1)
74. int a = 22, b = 5; (a >> 1) + (b << 1)
75. int a = 12, b = 10; a ^ (b >> 1)
76. int a = 7; (a << 1) - (a >> 1)
77. int a = 5, b = 2; ~(a & b)
78. int a = 18, b = 9; a | (b << 1)
79. int a = 10, b = 3; (a >> 1) ^ (b << 1)
80. int a = 28, b = 6; (a & 3) + (b | 4)

81–100 Mixed Hard Expressions

81. int a = 12, b = 4, c = 2; a + b * c - a / b


82. int a = 9, b = 3; double x = 2.5; a / b + x * b
83. int a = 7, b = 2, c = 5; a * b % c + b
84. int a = 10, b = 3; double x = 4.2; a % b + (int)x
85. int a = 15, b = 5, c = 3; (a / b) * (b - c)
86. double x = 8.5; int a = 3; (int)x + a * 2
87. float f = 3.5f; int a = 4; a + (int)(f * a)
88. int a = 14, b = 6; (a / b) + (a % b)
89. int a = 8, b = 3, c = 7; a - b * c + b
90. double x = 12.6, y = 3.2; x / y + y
91. int a = 6, b = 2; (a + b) * (a - b)
92. int a = 4, b = 7, c = 2; a * b - c * a
93. double x = 5.5; int a = 8; a + (int)(x * a)
94. int a = 18, b = 5; a % b * (a / b)
95. int a = 20, b = 6; (a / 3) + (b % 4)
96. double x = 9.9; int a = 3; (int)x % a
97. int a = 7, b = 4, c = 3; a % (b - c)
98. double x = 13.2; int a = 4; (int)(x / a) + a
99. int a = 21, b = 5; (a % b) + (a / b)
100. int a = 9, b = 2; double x = 3.5; a / b + (int)x

If you want, I can also provide:


✅100 MCQs – Input in Java & Math Library
(Class 9 ICSE)
(Each question has 4 options in the next line)

INPUT IN JAVA (1–50 MCQs)

1. Which package is needed to use Scanner class?


D. [Link] C. [Link] B. [Link] A. [Link]
2. Which class is commonly used for keyboard input in Java?
D. Input C. Buffer B. Scanner A. Reader
3. To read integer input from user, which method is used?
D. readInt() C. nextInt() B. next() A. nextFloat()
4. Which statement correctly creates a Scanner object?
D. new Scanner sc C. Scanner sc = new Scanner([Link]); B. Scanner sc = new
Scanner(); A. Scanner sc = Scanner([Link]);
5. nextLine() reads:
D. A number C. A whole line B. A boolean A. A single word
6. To read a decimal number we use:
D. doubleInput() C. readDouble() B. nextDouble() A. nextDecimal()
7. Which method reads a single word?
D. read() C. next() B. nextString() A. nextWord()
8. What does [Link] represent?
D. Scanner C. Storage B. Input stream A. Output device
9. Which input method returns true/false?
D. nextLine() C. nextFloat() B. nextBoolean() A. nextInt()
10. next().charAt(0) is used to read:
D. String C. Double B. Character A. Integer
11. Which input method reads a float value?
D. nextVal() C. nextFloat() B. nextDigit() A. next()
12. Which keyword is used for user input?
D. Scanner C. input B. scan A. entry
13. What must be imported to use Scanner?
D. [Link].* C. [Link].* B. [Link].* A. [Link].*
14. Scanner sc = new Scanner([Link]); — sc is:
D. Package C. Variable B. Method A. Object
15. nextDouble() returns a value of type:
D. string C. double B. float A. int
16. To read a string with spaces, we use:
D. next() C. nextLine() B. nextWord() A. nextString()
17. Which input method may skip input after a number?
D. nextFloat() C. nextInt() B. next() A. nextLine()
18. Which of the following is NOT a Scanner method?
D. nextDouble() C. nextLine() B. nextChar() A. nextInt()
19. next() stops reading when it finds:
D. Equal sign C. Digit B. Space A. A dot
20. Which input method is used for reading long integers?
D. nextDigit() C. nextL() B. nextBigInt() A. nextLong()
21. Which statement is correct to read a boolean value?
D. [Link]() C. [Link]() B. [Link]() A. [Link]()
22. nextFloat() returns:
D. character C. integer B. 64-bit float A. 32-bit float
23. Which keyword creates objects?
D. object C. make B. new A. create
24. To close Scanner, we use:
D. [Link]() C. [Link]() B. [Link]() A. [Link]()
25. Which input method throws an exception on invalid input?
D. nextChar() C. nextInt() B. next() A. nextLine()
26. Which method reads short values?
D. nextSmall() C. readShort() B. nextShort() A. nextS()
27. The Scanner class belongs to:
D. [Link] C. [Link] B. [Link] A. [Link]
28. Which input method reads byte?
D. nextTiny() C. nextChar() B. nextSmall() A. nextByte()
29. What is the output of nextLine() after nextInt()?
D. Skips input C. Reads number again B. Reads old line break A. Reads next
line
30. To read a character input, we use:
D. [Link]() C. [Link]() B. [Link]().charAt(0) A. [Link]()
31. The Scanner class is part of:
D. Compiler C. JRE B. JVM A. JDK
32. [Link] is of type:
D. Reader C. Scanner B. File A. InputStream
33. What is the return type of next()?
D. boolean C. int B. String A. char
34. To take input from a file, we use:
D. Input(Scanner) C. readFile() B. FileInput() A. Scanner(File)
35. [Link]() returns:
D. String C. char B. boolean A. float
36. The default input device is:
D. Scanner C. Keyboard B. Printer A. Screen
37. Scanner sc = new Scanner("Hello"); — Input source is:
D. Console C. String B. Keyboard A. File
38. The next token means:
D. Next file C. Next number B. Next word A. Next character
39. next() ignores:
D. Numbers C. Words B. Characters A. Spaces
40. Which reads scientific notation?
D. nextLine() C. nextInt() B. nextDouble() A. nextSci()
41. [Link]() returns:
D. string C. number B. boolean A. int
42. Which Scanner method checks next float?
D. isFloat() C. canFloat() B. nextFloat() A. hasNextFloat()
43. To read a single word:
D. read() C. nextLine() B. nextOne() A. next()
44. new Scanner([Link]) is called:
D. Operator C. Loop B. Method A. Constructor
45. Which input method allows spaces?
D. nextWord() C. nextLine() B. nextDouble() A. next()
46. Scanner works on:
D. Classes C. Loops B. Arrays A. Streams
47. Scanner can be used for:
D. Keyboard, files, strings C. Strings only B. Files only A. Keyboard only
48. To read an entire paragraph we use:
D. next() C. read() B. nextLine() A. nextPara()
49. Which method reads token as double?
D. readDouble() C. nextReal() B. nextDouble() A. nextFloat()
50. Which method reads input until space?
D. read() C. nextPara() B. nextLine() A. next()

MATH LIBRARY (51–100 MCQs)

51. Math class is in package:


D. [Link] C. [Link] B. [Link] A. [Link]
52. Which method finds square root?
D. Math.pow2() C. [Link]() B. [Link]() A. [Link]()
53. [Link](2,3) returns:
D. 10 C. 8 B. 6 A. 5
54. [Link](-7) returns:
D. -1 C. 7 B. 0 A. -7
55. Which returns the greater value?
D. [Link]() C. [Link]() B. [Link]() A. [Link]()
56. Which returns the smaller value?
D. [Link]() C. [Link]() B. [Link]() A. [Link]()
57. Value of [Link](49) is:
D. 3 C. 7 B. 14 A. 49
58. [Link](5,0) returns:
D. 25 C. 5 B. 1 A. 0
59. [Link](4.7) returns:
D. 3 C. 6 B. 5 A. 4
60. [Link](4.2) returns:
D. 3.0 C. 4.2 B. 4.0 A. 5.0
61. [Link](6.9) returns:
D. 5.0 C. 6.0 B. 6.9 A. 7.0
62. [Link](-12.5) returns:
D. 13 C. 12 B. 12.5 A. -12.5
63. [Link]() generates:
C. 0.0 to B. 0 to 1 A. 1 to 10 <D. -1 to 1 1.0
64. The return type of [Link]() is:
D. double C. boolean B. int A. float
65. [Link](3,2) equals:
D. 12 C. 9 B. 8 A. 6
66. [Link](4,9) returns:
D. 1 C. 13 B. 9 A. 4
67. [Link](8,3) returns:
D. -5 C. 5 B. 8 A. 3
68. [Link](64) equals:
D. 9 C. 8 B. 7 A. 6
69. [Link](10,1) is:
D. 10 C. 5 B. 1 A. 0
70. [Link](3.01) gives:
D. 2.0 C. 3.01 B. 3.0 A. 4.0
71. What is [Link](5.99)?
D. 4.0 C. 5.0 B. 5.99 A. 6.0
72. [Link](3.2) returns:
D. 5 C. 2 B. 4 A. 3
73. [Link](3.5) returns:
D. 6 C. 5 B. 4 A. 3
74. Which gives remainder?
D. [Link]() C. % B. modulus() A. [Link]()
75. [Link]()*10 generates numbers from:
D. 10–20 C. 0–9 B. 0–10 A. 1–10
76. [Link](2,4) is:
D. 20 C. 16 B. 12 A. 8
77. [Link](1) equals:
D. 3 C. 2 B. 1 A. 0
78. Math class methods are:
D. Local methods C. Static methods B. Instance methods A. Object methods
79. [Link](0) is:
D. Undefined C. -1 B. 1 A. 0
80. [Link](2.5,2.4) is:
D. 0.1 C. 5 B. 2.5 A. 2.4
81. [Link](-3,-8) returns:
D. 3 C. 5 B. -8 A. -3
82. [Link](-4.2) returns:
D. 5.0 C. 4.2 B. -4.0 A. -5.0
83. [Link](-4.2) returns:
D. 4.2 C. -4.2 B. -5.0 A. -4.0
84. Which function returns power?
D. [Link]() C. [Link]() B. [Link]() A. [Link]()
85. What is [Link](0)?
D. Error C. Undefined B. 1 A. 0
86. [Link]()*5 produces:
D. 1–4 C. 1–5 B. 0–5 A. 0–4
87. [Link](-100) gives:
D. 10 C. 0 B. 100 A. -100
88. The Math class belongs to which package?
D. [Link] C. [Link] B. [Link] A. [Link]
89. What is [Link](4,0.5)?
D. 1 C. 8 B. 4 A. 2
90. [Link](7.8f) returns:
D. 10 C. 9 B. 8 A. 7
91. [Link](2.0) returns:
D. 1 C. 3.0 B. 2.0 A. 2
92. [Link](2.0) returns:
D. 0.0 C. 3.0 B. 1.0 A. 2.0
93. [Link](0,5) is:
D. Undefined C. 5 B. 1 A. 0
94. [Link](16.0) returns:
D. 16.0 C. 8.0 B. 4.0 A. 2.0
95. [Link](5.6,5.60) is:
D. None C. Both same B. 5.60 A. 5.6
96. [Link](-2,-3) gives:
D. 2 C. 0 B. -3 A. -2
97. [Link](4.0001) returns:
D. 5.0 C. 3.0 B. 4.1 A. 4.0
98. [Link](9.0001) returns:
D. 8.0 C. 9.0001 B. 10.0 A. 9.0
99. [Link](9.49) returns:
D. 11 C. 8 B. 10 A. 9
100. [Link](9.50) returns:
D. 12 C. 11 B. 10 A. 9

✅100 Fill in the Blanks — Java Input & Math


Library (Class 9 ICSE)
1. The class used to take input from the keyboard in Java is __________.
2. To use the Scanner class, we must write the statement __________ at the top of the
program.
3. The object of Scanner class is usually created using the keyword __________.
4. The method to read an integer using Scanner is __________.
5. The method to read a double value using Scanner is __________.
6. The method to read a single word using Scanner is __________.
7. The method to read a full line of text using Scanner is __________.
8. The method to read a boolean value using Scanner is __________.
9. The method to read a float value using Scanner is __________.
10. The method to read a long value using Scanner is __________.
11. The method to read a short value using Scanner is __________.
12. The method to read a byte value using Scanner is __________.
13. Scanner class belongs to the package __________.
14. A package in Java is a collection of related __________.
15. Input functions of Scanner are also called __________ methods.
16. To read input, the object name must be followed by a __________.
17. The Math class belongs to the package __________.
18. The method to find square root of a number is __________.
19. The method to find power of a number is __________.
20. The method to find maximum of two numbers is __________.
21. The method to find minimum of two numbers is __________.
22. The method that returns absolute value is __________.
23. The method to generate a random number is __________.
24. The range of [Link]() is from __________ to __________.
25. The method to round a decimal number is __________.
26. The method that returns the largest integer less than a number is __________.
27. The method that returns the smallest integer greater than a number is __________.
28. The Math class contains only __________ methods.
29. The Math class methods are __________ by default.
30. [Link]() returns a value of type __________.
31. [Link]() returns a value of type __________.
32. [Link]() returns a value of type __________.
33. [Link](-9) returns __________.
34. [Link](4, 9) returns __________.
35. [Link](4, 9) returns __________.
36. [Link](4.2) returns __________.
37. [Link](7.9) returns __________.
38. [Link](4.6) returns __________.
39. [Link](4.3) returns __________.
40. Scanner sc = new Scanner([Link]); here sc is a __________.
41. In Scanner, [Link] represents the __________ device.
42. [Link] is a constant representing the value of __________.
43. Math.E is a constant representing the base of __________.
44. [Link](2, 3) returns __________.
45. [Link](49) returns __________.
46. [Link](-12.5) returns __________.
47. [Link]() * 10 generates values between __________ and __________.
48. Scanner input cannot read input without creating a __________.
49. Math methods can be accessed without creating __________.
50. The method used to convert string to int is __________.
51. The method used to convert string to double is __________.
52. Wrapper class of int is __________.
53. Wrapper class of double is __________.
54. Wrapper class of char is __________.
55. The function [Link]() returns a value of type __________.
56. The function [Link]() returns a value of type __________.
57. The Scanner method nextLine() returns a __________ value.
58. The method next() stops reading input at __________.
59. Java input using Scanner is called __________ input.
60. [Link](9, 0.5) is equal to __________.
61. The method used to find cube root is __________.
62. [Link](27) gives __________.
63. [Link](180) returns __________.
64. [Link]([Link]) returns __________.
65. [Link](0) returns __________.
66. [Link](0) returns __________.
67. [Link](0) returns __________.
68. [Link](1) returns __________.
69. [Link](1) returns __________.
70. The Scanner method nextBoolean() returns either __________ or __________.
71. In Java, user input is taken at __________ time.
72. [Link](5, 2) is equal to __________.
73. [Link](100) is equal to __________.
74. [Link](0) is equal to __________.
75. [Link]() never returns the value __________.
76. The data type returned by [Link](3.8f) is __________.
77. The data type returned by [Link](3.8) is __________.
78. [Link](-2.3) returns __________.
79. [Link](-2.3) returns __________.
80. Scanner can read values from __________ device.
81. A Java program must import Scanner from __________ package.
82. Input mismatch causes __________ error.
83. Math class is part of __________ library.
84. nextLine() reads input until it finds __________.
85. next() reads input until it finds __________.
86. The method to read a character using Scanner indirectly is __________.
87. [Link] is used to take __________ input.
88. [Link](16, 0.25) returns the __________ root of 16.
89. [Link](-8) returns __________.
90. [Link](0) returns __________.
91. [Link](5) returns __________.
92. [Link](3, 4) returns __________.
93. [Link]('A', 'B') compares their __________ values.
94. Scanner method nextShort() returns value of type __________.
95. Scanner method nextByte() returns value of type __________.
96. [Link](3, -1) returns __________.
97. [Link](Integer.MIN_VALUE) gives __________.
98. [Link](10, 3) returns __________.
99. The method [Link]() takes exactly __________ arguments.
100. Scanner class is used for __________ input in Java.

✅50 Two-Marks Questions With Answers (No


Blank Lines)
1. What is the purpose of the Scanner class in Java?
Answer: Scanner is used to take input from the user through the keyboard.
2. Why must we write import [Link]; in a program?
Answer: It allows Java to access the Scanner class found in the [Link] package.
3. Write the statement to create a Scanner object.
Answer: Scanner sc = new Scanner([Link]);
4. What is the difference between next() and nextLine()?
Answer: next() reads a single word; nextLine() reads the entire line including
spaces.
5. Which method of Scanner is used to read an integer?
Answer: nextInt()
6. What does [Link]() do?
Answer: It returns the square root of a number.
7. What does [Link](2, 3) return?
Answer: 8.0
8. What is the range of [Link]()?
Answer: 0.0 (inclusive) to 1.0 (exclusive)
9. What is the return type of [Link]()?
Answer: double
10. What does [Link](-5) return?
Answer: 5
11. State the purpose of [Link](a, b).
Answer: It returns the larger of the two values.
12. State the purpose of [Link](a, b).
Answer: It returns the smaller of the two values.
13. What does [Link](4.3) return?
Answer: 5.0
14. What does [Link](7.8) return?
Answer: 7.0
15. What does [Link](4.6) return?
Answer: 5
16. What type of value does [Link]() accept?
Answer: double
17. What does [Link] represent?
Answer: The standard input device (keyboard).
18. Can Math class methods be used without objects? Why?
Answer: Yes, because Math methods are static.
19. What does [Link](9, 0.5) return?
Answer: 3.0
20. What does [Link](27) return?
Answer: 3.0
21. Which Scanner method reads boolean values?
Answer: nextBoolean()
22. What does [Link](180) return?
Answer: π (3.14159…)
23. Output of [Link]('A', 'B'):
Answer: 'B'
24. Name the wrapper class of int.
Answer: Integer
25. Name the wrapper class of double.
Answer: Double
26. Why is parseInt() used?
Answer: To convert a string to an integer.
27. What does [Link](144) return?
Answer: 12.0
28. What does [Link]() * 10 return?
Answer: A number from 0 to <10
29. Which method reads a float?
Answer: nextFloat()
30. Which method reads a long?
Answer: nextLong()
31. What does Math.E represent?
Answer: The constant e (2.718...)
32. What does [Link] represent?
Answer: The constant π (3.14159…)
33. What is the return type of [Link]()?
Answer: double
34. Give example using nextDouble().
Answer: double n = [Link]();
35. What does [Link](0) return?
Answer: 0.0
36. What does [Link](0) return?
Answer: 1.0
37. What does [Link](0) return?
Answer: 0.0
38. Output of [Link](5.2):
Answer: 5
39. Output of [Link](5.7):
Answer: 6
40. What does nextByte() read?
Answer: A byte value.
41. Why must we import the Scanner class?
Answer: Because it is not included in [Link].
42. Output of [Link](-19.6):
Answer: 19.6
43. What does [Link](3, 4) calculate?
Answer: √(3² + 4²) = 5.0
44. Output of [Link](-2.3):
Answer: -2.0
45. Output of [Link](-2.3):
Answer: -3.0
46. What does nextShort() read?
Answer: A short integer value.
47. What does [Link](-5) return?
Answer: -1.0
48. What does [Link](0) return?
Answer: 0.0
49. Output of [Link](3, 4):
Answer: 81.0
50. Output of [Link](2):
Answer: Approximately 1.41421356
✅JAVA INPUT & MATHEMATICAL
LIBRARY
EASY LEVEL – 50 MARKS QUESTION PAPER

Section A – Very Short Questions (1 mark × 10 = 10 marks)

1. Name the package of Scanner class.


2. Write an example of creating a Scanner object.
3. Which Scanner method reads an integer?
4. Which method returns the square root of a number?
5. Write the output of: [Link](3, 9)
6. Write the output of: [Link](-7)
7. What is the range of [Link]()?
8. Which method reads a double input?
9. What does [Link] represent?
10. Write the output of: [Link](4.4)

Section B – Short Questions (2 marks × 10 = 20 marks)

11. Define the purpose of the Scanner class with an example.


12. Distinguish between next() and nextLine() methods.
13. Write two Math class methods for rounding values and explain them.
14. What is the difference between [Link]() and [Link]()?
15. Write a statement to read (i) a float (ii) a long using Scanner.
16. Why can Math class methods be used without creating an object?
17. Write the output of:
[Link](5.2)
[Link](5.2)
18. What does [Link](2, 4) return? Explain.
19. Write two statements using Scanner to input your name and age.
20. What is the use of [Link](a, b)? Give an example.

Section C – Short Answer Questions (3 marks × 5 = 15 marks)

21. Explain any three input methods of the Scanner class with examples.
22. State the function and give examples of the following Math methods:
(a) [Link]()
(b) [Link]()
(c) [Link]()
23. Write a Java code snippet to input three integers and find their average using Math
functions (use [Link]()).
24. State the difference between [Link](), [Link](), and [Link]() with
examples.
25. Write a program snippet to read the radius of a circle and display its area using [Link].
Section D – Long Answer Questions (5 marks × 1 = 5 marks)

26. Write a Java program to:


(a) Read two numbers using Scanner
(b) Find and print:
• Square root of the first number
• Power (first number raised to second number)
• Absolute value of second number
(c) Generate and display one random number between 1 and 10.

✅JAVA INPUT & MATHEMATICAL


LIBRARY
MEDIUM LEVEL – 50 MARKS QUESTION PAPER

SECTION A – Very Short Questions (1 mark × 10 = 10 marks)

1. Write the syntax to import the Scanner class.


2. Name any one method used to read a String input.
3. Which Math method returns the cube root of a number?
4. Write the output of: [Link](12, 7)
5. Write the output of: [Link](7.8)
6. What is the return type of [Link]()?
7. Which method reads a boolean value from Scanner?
8. Write the output of: [Link](-15.6)
9. What does nextInt() do?
10. Write the value of: [Link](5, 2)

SECTION B – Short Answer Questions (2 marks × 10 = 20 marks)

11. Explain the use of nextDouble() and nextFloat() with examples.


12. Differentiate between:
(a) [Link](x)
(b) [Link](x)
13. Write any two rules of using the Math class in Java.
14. Give two differences between next() and nextLine().
15. Write the output of the following:
(i) [Link](8.1)
(ii) [Link](8.9)
16. What does [Link]() do? Give an example.
17. Write a Java statement to input an integer and a double value.
18. What will be the result of the following?
(i) [Link](400)
(ii) [Link](125)
19. Why is Scanner called a built-in class?
20. What is the difference between [Link]() and [Link]()? Explain with an
example.
SECTION C – Short Answer Questions (3 marks × 5 = 15 marks)

21. Write any three Scanner methods along with their purpose and examples.
22. Explain the use of the following Math methods with examples:
(a) sqrt()
(b) pow()
(c) abs()
23. Write a Java snippet to input three numbers and display the highest using
[Link]().
24. Using Math functions, write a code snippet to:
(a) Accept a number
(b) Find its square
(c) Find its square root
25. Write a Java snippet to input the base and height of a triangle and display its area
using [Link]().

SECTION D – Long Answer Question (5 marks × 1 = 5 marks)

26. Write a Java program using Scanner to:


(a) Input two double values
(b) Display:
• Their sum
• Their absolute difference
• Larger value using [Link]()
• Square root of the smaller number
(c) Generate and display a random number between 50 and 100.

JAVA INPUT & MATHEMATICAL


LIBRARY – HARD LEVEL QUESTION
PAPER (50 Marks)
Time: 1½ Hours
Subject: Computer Applications – Class 9 (ICSE)

SECTION A – Very Short Answer Questions (1 × 10 = 10 Marks)

(Answer each question in one line)

1. Write the purpose of [Link]() in Java.


2. Why is BufferedReader faster than Scanner?
3. What is returned by [Link]()?
4. State the data type returned by [Link]().
5. Which exception occurs during invalid integer input?
6. What is the range of values generated by (int)([Link]()*6)+1?
7. Expand JVM.
8. What is type casting?
9. Write the syntax to import the mathematical library in Java.
10. What does [Link](4.1) return?
SECTION B – Short Answer Questions (2 × 10 = 20 Marks)

(Attempt any 10)

11. Explain the difference between Scanner and BufferedReader with examples.
12. What is the role of InputStreamReader? Give one example.
13. Evaluate using Java rules: [Link](144) + [Link](2,3)
14. How does Java convert string input to numeric values? Explain with code.
15. What is an escape sequence? Write two examples used in input/output.
16. What is the use of [Link]()? Give example with negative values.
17. Explain the working of [Link]() with an example.
18. What is parsing? Why is it necessary while taking input?
19. Predict output: [Link]([Link]([Link](5,2),
[Link](16)));
20. Differentiate between [Link]() and [Link]() with examples.
21. Explain the purpose of using try–catch when taking input from user.
22. What is the function of nextLine() in Scanner? How is it different from next()?
23. Write Java code to input a double value and display its cube root.
24. What is a token? How does Scanner class use tokens?
25. Why is [Link]() commonly used in games?

SECTION C – Long Answer Questions (4 × 5 = 20 Marks)

(Attempt any 5)
26.

Explain with code:


(a) Reading input using Scanner
(b) Reading input using BufferedReader
Mention one advantage of each.
27.

Write a program to input three numbers and display the largest using [Link]() twice.
28.

Write a program to input a radius and compute:

 Area using [Link]


 Circumference using 2 * [Link] * r
Show formula and output format.
29.

Explain the use of at least six Mathematical library functions with syntax, return type and
example output.
30.

Input three sides of a triangle and:


 Check if triangle is valid
 If valid, find area using Heron’s formula using [Link]()
Write complete Java code.
31.

Write a program to input a number and display:

 Square root
 Cube
 Absolute value
Use Math library only.
32.

Explain how type conversion works between:

 String → int
 int → double
 double → int
Use examples of input and output.
100 MCQs – Conditional Constructs in Java
(Options in Same Line)
1. Which keyword is used for simple decision? A) if B) switch C) case D) break
2. The construct that checks multiple conditions is: A) if-else-if B) loop C) switch D)
break
3. The else part executes when: A) condition true B) condition false C) always D) none
4. A switch can have: A) unlimited cases B) 2 cases C) 4 cases D) 10 cases
5. Switch cannot use: A) int B) char C) float D) byte
6. Default in switch executes when: A) first case matches B) no case matches C) break
missing D) none
7. An if must contain: A) else B) condition C) break D) case
8. Which is a relational operator? A) >= B) && C) ++ D) =
9. == operator checks: A) equality B) assignment C) inequality D) none
10. Condition in if returns: A) boolean B) int C) char D) double
11. In if(a>b) a and b must be: A) comparable values B) strings C) arrays D) none
12. Statement inside if runs only when: A) true B) false C) null D) none
13. Default keyword in switch is: A) last block B) first block C) middle block D) none
14. Break in switch is used to: A) exit switch B) exit program C) skip input D) none
15. Condition expression type is: A) boolean B) int C) char D) float
16. Ternary operator symbol: A) ?: B) ++ C) && D) %
17. Ternary operator is used instead of: A) if-else B) switch C) loop D) break
18. Correct if syntax: A) if(condition) B) if condition C) if{condition} D) none
19. Mandatory in switch: A) case B) default C) break D) none
20. A condition always gives: A) boolean B) float C) int D) char
21. Count of else-if in ladder: A) unlimited B) only 1 C) only 2 D) none
22. Keyword for multiple fixed options: A) switch B) if C) break D) else
23. Invalid case value: A) 3.14 B) 10 C) 'A' D) 20
24. Default executes when: A) no case matches B) first matches C) break missing D)
none
25. Ternary operator uses operands: A) 3 B) 2 C) 1 D) 4
26. a==b means: A) equality B) assignment C) relation D) none
27. AND operator: A) && B) || C) ! D) %
28. OR operator: A) || B) && C) ! D) none
29. NOT operator: A) ! B) != C) =! D) --
30. a!=b means: A) not equal B) equal C) assign D) none
31. Else block runs when: A) condition false B) condition true C) always D) none
32. Nested if means: A) if inside if B) if inside loop C) if inside switch D) none
33. Boolean expression: A) 5==5 B) 5+5 C) "Hi" D) 10
34. Character comparison uses: A) == B) = C) === D) equal()
35. Case values must be: A) constants B) variables C) floats D) expressions
36. Which can be nested? A) if B) switch C) both D) none
37. Ternary returns: A) any value B) only int C) only boolean D) only numbers
38. First evaluated in ternary: A) condition B) true part C) false part D) none
39. if(5>3) is: A) true B) false C) error D) none
40. Switch performs: A) exact match B) string match only C) range check D) none
41. For range checking: A) if B) switch C) break D) case
42. Else belongs to: A) nearest if B) farthest if C) first if D) none
43. OR symbol is: A) || B) | C) & D) !
44. Boolean values: A) true/false B) 0/1 C) char D) int
45. if(true) is: A) valid B) invalid C) error D) none
46. Switch cannot take: A) double B) int C) char D) byte
47. Ternary written as: A) condition?value1:value2 B) ? condition : C) : ? D) none
48. Switch evaluated at: A) runtime B) compile-time C) both D) none
49. Missing break causes: A) fall-through B) error C) skip D) stop
50. Valid ternary form: A) a?b:c B) a:b?c C) a?b D) a?
51. For both conditions true: A) && B) || C) ! D) !=
52. String in switch uses: A) exact match B) > C) < D) =
53. Else cannot exist without: A) if B) switch C) case D) default
54. Complex decision uses: A) nested if B) switch C) break D) continue
55. Switch cannot check: A) range B) equality C) char D) int
56. if(10<5) is: A) false B) true C) error D) none
57. NOT operator symbol: A) ! B) !! C) !== D) none
58. != stands for: A) not equal B) equal C) assign D) none
59. Highest priority: A) ! B) && C) || D) =
60. Switch best used for: A) menu B) loops C) strings only D) arrays
61. Ternary replaces: A) if-else B) switch C) loop D) none
62. Logical operators work on: A) boolean B) char C) float D) string
63. Only one block among if-else runs: A) true B) false C) depends D) none
64. !(5==5) gives: A) false B) true C) error D) none
65. Multiple cases in switch handled by: A) many case labels B) if C) else D) none
66. Case ends with: A) break B) continue C) return D) goto
67. Deep if runs when: A) outer true B) outer false C) always D) none
68. Operator priority: A) ! > && > || B) && > ! > || C) || > && > ! D) none
69. Ternary must return: A) same type B) different types C) boolean D) int
70. Invalid switch type: A) float B) char C) byte D) short
71. Fall-through avoided using: A) break B) continue C) default D) if
72. True condition: A) 10==10 B) 5>8 C) 9<1 D) none
73. String comparison in switch is: A) equals() internally B) == C) > D) <
74. False condition: A) 10>20 B) 8==8 C) true D) !false
75. Condition inside if must be: A) boolean B) int C) char D) float
76. Ternary cannot replace: A) multiple nested if B) simple if C) simple if-else D)
compare
77. Switch checks: A) exact equality B) ranges C) conditions D) loops
78. Default position: A) anywhere B) top only C) bottom only D) middle only
79. OR gives true when: A) one true B) both false C) both false D) none
80. AND is false when: A) one false B) both true C) both true D) none
81. NOT flips: A) boolean B) int C) char D) string
82. If a=10, a==10: A) true B) false C) error D) none
83. Switch uses: A) == B) > C) < D) !=
84. Invalid case: A) 3.2 B) 2 C) 'x' D) 4
85. Ternary evaluates: A) condition first B) false first C) true first D) none
86. Nested if used for: A) dependent conditions B) loops C) input D) break
87. Range checking uses: A) && B) || C) ! D) none
88. true && false gives: A) false B) true C) error D) exception
89. true || false gives: A) true B) false C) error D) none
90. !false gives: A) true B) false C) error D) none
91. Switch checks: A) fixed value B) relation C) complex logic D) arithmetic
92. Ternary condition must be: A) boolean B) int C) float D) char
93. Both true in &&: A) true B) false C) error D) none
94. Left of OR true: A) right ignored B) right evaluated C) false D) none
95. Switch case cannot contain: A) variables B) literals C) constants D) chars
96. Else-if ladder used for: A) multiple choices B) one choice C) loops D) none
97. Break used in: A) loops and switch B) if C) else D) ternary
98. Ternary returns based on: A) true or false part B) condition only C) program D) none
99. Cases cannot have: A) duplicate values B) break C) print D) input
100. Switch expression must match: A) type B) size C) memory D) none
✅100 HARD FIND-THE-OUTPUT
QUESTIONS (Java – Conditional Constructs)
(No loops, only expressions & if/else/ternary conditions)

1.
int a = 5, b = 7;
if(a++ + ++b > 12) a = b - a;
[Link](a + ", " + b);

2.
int x = 10;
if(--x == x--) x += 5;
else x -= 5;
[Link](x);

3.
int a = 3, b = 4, c = 5;
if(a * b == c || ++a + b > c) c = a + b + c;
[Link](a + b + c);

4.
int n = 15;
if((n & 1) == 0) n += 2;
else n -= 3;
[Link](n);

5.
int a = 2, b = 3;
if((a++ * b--) > (b++ + a--)) b = a + b;
[Link](a + ":" + b);

6.
int a = 10, b = 20;
if((a < b) == (b > a)) a = b / a;
[Link](a);

7.
char c = 'A';
if(c + 32 == 'a') c = (char)(c + 1);
[Link](c);

8.
int x = 7;
if(x++ > 7 && ++x > 9) x += 2;
[Link](x);

9.
int x = 5;
if(x++ > 5 || ++x > 7) x *= 2;
[Link](x);

10.
int a = 9, b = 2;
if(a % b * b == 0) a /= b;
[Link](a);
11.
int a = 12;
if(a-- > 12) a += 3;
else a -= 3;
[Link](a);

12.
int x = 6, y = 6;
if(x++ == ++y) y += x;
[Link](x + y);

13.
double d = 12.5;
if(d == 12.50) d = d / 2;
[Link](d);

14.
int a = 2, b = 3;
if(a++ + ++b == 6) a = b = a + b;
[Link](a + "," + b);

15.
int n = -5;
if(n++ < 0) n *= -1;
[Link](n);

16.
int x = 10;
if(!(x > 5) || x++ == 10) x += 3;
[Link](x);

17.
int a = 8, b = 2;
if(a / b == b) b = a % b;
[Link](b);

18.
int x = 9;
if(x == 9)
if(x++ == 9)
x += 3;
[Link](x);

19.
int a = 5, b = 10;
if((a > b) ? a++ > 5 : b-- > 8) a = b;
[Link](a + " " + b);

20.
int a = 3;
if(a++ * 2 == 6 && --a == 3) a += 4;
[Link](a);

21–100 (80 MORE HARD QUESTIONS)

Continuing same format, compact list:

21.
int a = 4;
if(a++ + a++ == 9) a *= 2;
[Link](a);

22.
int x = 11;
if(--x + x-- == 20) x += 5;
[Link](x);

23.
int a = 10;
if(a / 3 * 3 == a - a % 3) a -= 2;
[Link](a);

24.
int a = 7;
if(a++ == 7 && ++a == 9) a++;
[Link](a);

25.
int x = 15;
if((x | 1) == 15) x--;
[Link](x);

26.
int x = 4, y = 5;
if(++x > y-- && y++ > x) x += y;
[Link](x + ":" + y);

27.
char c = 'z';
if(c - 32 == 'Z') c = '!';
[Link](c);

28.
int a = 1;
if(a++ == 1 || a++ == 2) a += 10;
[Link](a);

29.
int n = 10;
if((n & 2) != 0) n += 3;
[Link](n);

30.
int a = 9, b = 3;
if(a % b == 0 && (a / b) % 2 == 0) a = 1;
[Link](a);

31.
int x = 3;
if((x += 2) == 5) x *= 3;
[Link](x);

32.
int k = 10;
if(--k + k-- == 18) k = 100;
[Link](k);

33.
int a = 6, b = 4;
if(a > b ? a++ > 6 : b-- > 3) a = b;
[Link](a + "," + b);
34.
int x = 8;
if(x++ > 8 ^ ++x > 10) x--;
[Link](x);

35.
int a = 12;
if(a-- % 5 == 2) a *= 2;
[Link](a);

36.
int x = 5, y = 7;
if((x ^ y) == 2) x = y;
[Link](x);

37.
int a = 13;
if((a >> 1) == 6) a -= 3;
[Link](a);

38.
int x = 7;
if((x >>> 1) == 3) x += 2;
[Link](x);

39.
int a = 3;
if((a <<= 1) == 6) a++;
[Link](a);

40.
int a = 20;
if((a >>= 2) == 5) a += 5;
[Link](a);

41–100 (60 questions)

Below are the rest compactly:

41.
int a = 5, b = 9;
if(a + b > 10 && a++ < 5) b--;
[Link](a + b);

42.
int x = 3;
if(++x == 4 || x++ == 5) x += 2;
[Link](x);

43.
int n = 8;
if(n-- > 8 && ++n == 8) n = 0;
[Link](n);

44.
int a = 6;
if((a % 2 == 0) && (a / 2 == 3)) a += 4;
[Link](a);
45.
double d = 10.0;
if(d++ == 10) d *= 1.1;
[Link](d);

46.
int x = 1;
if((x = x + 2) == 3) x += 3;
[Link](x);

47.
int x = 7, y = 2;
if(x % y == 1 && (x / y) == 3) y += x;
[Link](y);

48.
boolean b = false;
if(b = true) [Link](1);
else [Link](0);

49.
int p = 3;
if((p += 3) > 5) p -= 2;
[Link](p);

50.
char c = 65;
if(++c == 'B') [Link](c);

51.
int a = 9, b = 4;
if (a / b == 2 && a % b == 1) a++;
[Link](a);

52.
int x = 5;
if ((x += 5) == 10) x--;
[Link](x);

53.
int k = 7;
if (k++ == 7 && k++ == 8) k += 2;
[Link](k);

54.
char c = 'a';
if (c - 32 == 'A') c++;
[Link](c);

55.
int n = 13;
if ((n & 4) == 4) n--;
[Link](n);

56.
int x = 6;
if ((x | 2) == 6) x += 3;
[Link](x);

57.
int a = 5;
if ((a ^ 1) == 4) a *= 2;
[Link](a);

58.
int x = 2;
if ((x << 2) == 8) x++;
[Link](x);

59.
int p = 10;
if ((p >> 1) == 5) p--;
[Link](p);

60.
int q = 3;
if ((q >>> 1) == 1) q += 4;
[Link](q);

61.
int a = 15;
if ((a & 1) == 1) a--;
[Link](a);

62.
int x = 4;
if (--x == 2) x += 5;
[Link](x);

63.
int y = 9;
if (y++ > 8 && ++y > 10) y++;
[Link](y);

64.
int k = 5;
if (k++ > 5 || k++ > 6) k += 2;
[Link](k);

65.
int n = 6;
if ((n %= 4) == 2) n += 3;
[Link](n);

66.
double d = 5.5;
if ((int)d == 5) d++;
[Link](d);

67.
char c = 'D';
if (c + 1 == 'E') [Link](c);

68.
int m = 8;
if ((m / 2 * 2) == m) m--;
[Link](m);

69.
int a = 3, b = 5;
if (a * b == 15) b -= 2;
[Link](b);
70.
int x = 10;
if ((x -= 3) == 7) x += 4;
[Link](x);

71.
int n = 17;
if ((n % 4) == 1) n += 3;
[Link](n);

72.
int a = 5;
if ((a += 2) == 7) a *= 2;
[Link](a);

73.
int x = 8;
if (x++ > 8 && x++ > 9) x += 3;
[Link](x);

74.
int y = 4;
if (++y == 5 && y++ == 5) y += 2;
[Link](y);

75.
int a = 10;
if ((a / 3) == 3 && a % 3 == 1) a--;
[Link](a);

76.
char c = 'M';
if (c - 1 == 'L') c++;
[Link](c);

77.
int k = 2;
if ((k *= 3) == 6) k--;
[Link](k);

78.
int p = 9;
if ((p | 1) == 9) p--;
[Link](p);

79.
int r = 6;
if ((r & 2) == 2) r += 4;
[Link](r);

80.
int x = 3;
if ((x ^ 3) == 0) x += 5;
[Link](x);

81.
int a = 12;
if ((a >> 2) == 3) a += 2;
[Link](a);
82.
int b = 8;
if ((b << 1) == 16) b--;
[Link](b);

83.
int x = 5;
if (x++ == 5 && x-- == 6) x += 3;
[Link](x);

84.
int y = 3;
if (++y == 4 || y++ == 4) y += 2;
[Link](y);

85.
double d = 9;
if ((d / 3) == 3) d -= 1.5;
[Link](d);

86.
int k = 7;
if ((k & 3) == 3) k++;
[Link](k);

87.
char c = 'X';
if (c + 2 == 'Z') c = '*';
[Link](c);

88.
int a = 6;
if ((a *= 2) == 12) a += 3;
[Link](a);

89.
int n = 5;
if ((n += 5) > 9) n--;
[Link](n);

90.
int x = 4;
if ((x | 4) == 4) x += 3;
[Link](x);

91.
int a = 11;
if ((a & 2) == 2) a++;
[Link](a);

92.
int b = 14;
if ((b % 4) == 2) b -= 3;
[Link](b);

93.
int x = 9;
if (--x == 8 && x-- == 8) x++;
[Link](x);

94.
char c = 'b';
if (c - 1 == 'a') c = 'Z';
[Link](c);

95.
int m = 10;
if ((m /= 2) == 5) m *= 3;
[Link](m);

96.
int p = 3;
if ((p << 2) == 12) p++;
[Link](p);

97.
double d = 4.9;
if ((int)d == 4) d += 2;
[Link](d);

98.
int r = 7;
if ((r ^ 2) == 5) r--;
[Link](r);

99.
int a = 6;
if ((a & 1) == 0) a += 4;
[Link](a);

100.
int x = 2;
if (++x == 3 && x++ == 3) x += 5;
[Link](x);

✅Conditional Constructs in Java – 50


Questions (2 Marks Each) with Answers
1. What is a conditional construct in Java? Give an example.

Answer: A conditional construct allows execution of statements based on conditions.


Example:
if (a > b) [Link]("A");

2. Write the syntax of an if–else statement.

Answer:
if (condition) {
statements;
} else {
statements;
}
3. What is the purpose of the else block in Java?

Answer:
The else block executes when the condition in the if statement evaluates to false.

4. What is a nested if statement?

Answer:
An if statement written inside another if statement is called a nested if.

5. Write an example of a nested if.

Answer:
if(a > 0){
if(a % 2 == 0) [Link]("Even");
}

6. What is the difference between if and else-if?

Answer:
if checks the first condition; else-if checks another condition only if previous conditions are
false.

7. Why is else-if preferred over multiple if statements?

Answer:
Because else-if avoids checking unnecessary conditions and makes code faster.

8. Write the syntax of an else-if ladder.

Answer:
if(a>0) { }
else if(a<0) { }
else { }

9. Define conditional operator.

Answer:
It is a shorthand form of if-else using ?:.

10. Give an example of conditional operator.

Answer:
int x = (a > b) ? a : b;

11. What is the output of: (a=5)? a>3? "Yes":"No"

Answer: Yes
12. Define switch statement.

Answer:
It is a multi-way branch statement that selects code based on value of an expression.

13. Write the syntax of switch.

Answer:
switch(x){
case 1: ;
break;
default: ;
}

14. Why is break used in switch?

Answer:
To stop fall-through and exit from switch.

15. What happens if break is missing in a case?

Answer:
Execution continues to the next case (fall-through).

16. Can switch work with String?

Answer:
Yes, Java allows String in switch since Java 7.

17. Can switch use relational operators?

Answer:
No, switch cannot use >, <, >=, <=.

18. Write a switch statement to print day name for day=2.

Answer:
switch(day){
case 2: [Link]("Tuesday");
}

19. What is default case used for?

Answer:
Runs when none of the case values match.
20. What is fall-through?

Answer:
When execution enters one case and continues to next case because break is missing.

21. Write an example of fall-through.

Answer:
switch(a){
case 1: [Link]("One");
case 2: [Link]("Two");
}

22. What is the output of:


int a = 10;
if(a == 10) ;
[Link]("Hello");

Answer: Hello (empty if statement)

23. What is the output of:


int a = 5;
if(a > 10)
[Link]("A");
else
[Link]("B");

Answer: B

24. What is brace-less if statement?

Answer: if statement written without {} when only one statement follows.

25. Write an example of brace-less if.

Answer:
if(a>0) [Link]("Positive");

26. Can switch have duplicate case values?

Answer: No.

27. What data types are allowed in switch?

Answer: byte, short, int, char, String, enum.

28. What is the output of:


int x = 7;
if(x % 2 == 1)
[Link]("Odd");
Answer: Odd

29. How many else-if statements can you use?

Answer: Unlimited.

30. What is short-circuit evaluation?

Answer: Java stops evaluating expressions once final result is known (in && and ||).

31. Give example of short-circuit use.

Answer:
if(a!=0 && b/a > 2)

32. What is the output of:


int a=5, b=3;
[Link](a>b ? a-b : b-a);

Answer: 2

33. Can we use float in switch?

Answer: No.

34. Write a conditional operator to find smallest of two numbers.

Answer:
int s = (a < b) ? a : b;

35. Write a program snippet to check leap year using if.

Answer:
if(year%4==0)
[Link]("Leap");

36. What is the purpose of nested switch?

Answer:
A switch inside another switch for multi-level decision-making.

37. Write example of nested switch.

Answer:
switch(a){
case 1:
switch(b){
case 2: [Link]("OK");
}
}

38. What is the output of:


int a = 0;
if(a==0)
if(a<5) [Link]("X");
else [Link]("Y");

Answer: X

39. What is dangling else?

Answer:
Confusion of which if the else belongs to in nested if (resolved by Java automatically).

40. Why should we avoid deeply nested if?

Answer:
Reduces readability and increases complexity.

41. Write an example of else-if ladder for grade.

Answer:
if(m>=90) [Link]("A");
else if(m>=80) [Link]("B");
else [Link]("C");

42. What is the output of:


char ch='A';
switch(ch){
case 'B': [Link]("B"); break;
default: [Link]("Other");
}

Answer: Other

43. When is default executed?

Answer:
When no case matches.

44. Give an example where switch is better than else-if ladder.

Answer:
When checking many constant values such as menu selection.
45. What is unreachable code in switch?

Answer:
Code that cannot be executed (e.g., statements after break).

46. What does this print?


int n = -5;
if(n < 0)
[Link]("Negative");
else
[Link]("Positive");

Answer: Negative

47. Can we use boolean in switch?

Answer:
No, Java does not allow boolean in switch.

48. What is the output?


int a=3, b=5;
[Link]((a>b)? "A" : "B");

Answer: B

49. Why is indentation important in conditional statements?

Answer:
Improves readability, prevents logical errors.

50. Compare switch and else-if ladder (any two differences).

Answer:

1. switch checks only equality; else-if checks range and comparisons.


2. switch is faster for many constant values.
✅100 IF–ELSE PROGRAMS IN JAVA (Easy
→ Hard)

🔹 PART A: EASY LEVEL (1–30)


(Basic conditions, comparisons, small arithmetic checks)

1. Check if a number is positive or negative.


2. Check if a number is even or odd.
3. Check if a number is divisible by 5.
4. Check if a number is divisible by 10.
5. Check if a number is divisible by both 3 and 5.
6. Check if a number is greater than 100.
7. Check if age ≥ 18 (eligible to vote).
8. Check if two numbers are equal.
9. Find the greater of two numbers.
10. Check if a number is a single-digit number.
11. Check if a number is a three-digit number.
12. Check if the last digit of a number is 7.
13. Check if a number ends with 0.
14. Check if a character is uppercase.
15. Check if a character is lowercase.
16. Check if a character is a digit.
17. Check if a character is a vowel or consonant.
18. Check if a year is leap year (simple: divisible by 4).
19. Check if a student passed (marks ≥ 40).
20. Check if marks ≥ 90 (grade A).
21. Check if a number is between 1 and 50.
22. Check if a number is multiple of 8.
23. Check if temperature > 30 (hot).
24. Check if a number is positive, negative, or zero.
25. Check if three numbers are equal.
26. Check if entered password matches “1234”.
27. Check if a number is prime (for small numbers).
28. Check if the first number is divisible by second number.
29. Find the smallest of two numbers.
30. Check if sum of two numbers is even.

🔹 PART B: MEDIUM LEVEL (31–70)


(Nested if, else-if ladder, mathematical logic, strings)

31. Find the largest among three numbers.


32. Find the smallest among three numbers.
33. Check if a number is within the range 100–999.
34. Check if a number is an Armstrong number (3 digits).
35. Check if a number is a perfect number.
36. Check if a number is a palindrome (3 digits).
37. Check if a triangle is valid (sum of two sides > third).
38. Check type of triangle (equilateral / isosceles / scalene).
39. Check if a person is child, adult, or senior (else-if).
40. Display grade using else-if (A/B/C/D/E).
41. Check if character is alphabet, digit, or special symbol.
42. Check if two numbers are co-prime.
43. Check if a number is prime (general logic).
44. Check if a number is composite.
45. Check if sum of digits is even or odd.
46. Check if a number is buzz number (multiple of 7 or ends with 7).
47. Check if a given day number 1–7 corresponds to weekday/weekend.
48. Check if a student is eligible for exam (attendance > 75%).
49. Calculate discount based on purchase amount.
50. Check profit or loss from CP & SP.
51. Check if roots of quadratic equation are real or imaginary.
52. Menu-driven: + – * / based on operator input.
53. Input month number → print number of days.
54. Check if a number is divisible by 11 using alternating sum rule.
55. Check if a letter is alphabetically before ‘m’.
56. Check if two strings are same or different.
57. Compare two strings lexicographically.
58. Check if a password is strong (length ≥ 8).
59. Determine ticket price based on age group.
60. Find maximum of four numbers (nested if).
61. Check if a character is a whitespace.
62. Check if input is "yes" or "no".
63. Check if a student qualifies for scholarship (marks + attendance).
64. Check if a number is a special number (sum of factorial digits).
65. Check if three sides form a right triangle.
66. Check if number contains digit 5.
67. Check if number is harshad number (divisible by sum of digits).
68. Check if birth year makes user adult (>18).
69. Validate electricity bill units (positive only).
70. Compare two floating-point numbers for equality (difference < 0.001).

🔹 PART C: HARD LEVEL (71–100)


(Complex logic, multiple conditions, nested decisions, trick problems)

71. Check if the entered time (HH, MM) is valid.


72. Check if a date (DD, MM, YYYY) is valid.
73. Determine zodiac sign from date of birth (nested if).
74. Check if two numbers have same last digit.
75. Check if sum of any two sides > third (triangle validity all checks).
76. Identify shape based on angles (right, acute, obtuse).
77. Check if a 4-digit number is a lucky number (sum of first 2 digits = last 2 digits).
78. Check if a number has unique digits (no repeat).
79. Check if a shopping coupon is applicable (amount + code match).
80. Check if a number is binary (only 0 and 1).
81. Check if three numbers form an AP, GP, or neither.
82. Check if a string ends with “.com”.
83. Validate a username (only alphabets and numbers allowed).
84. Validate email (must contain @ and .).
85. Calculate income-tax based on slabs (multiple else-if).
86. Determine water bill based on consumption slabs.
87. Check if a point (x, y) lies on x-axis, y-axis, or origin.
88. Check if a point lies inside, outside, or on a circle.
89. Check if a 3-digit number is an ascending number (digits increasing).
90. Check if a 3-digit number is a descending number.
91. Check if the three digits of a number form a Pythagorean triplet.
92. Check if given time (hr, min, sec) → AM or PM.
93. Check if a student qualifies for sports team (BMI + age + skills).
94. Evaluate logical expression result based on three variables.
95. Check if number is "Evil number" (binary has even number of 1s).
96. Check if string is palindrome (without loops; using charAt).
97. Determine type of license a person gets based on age + test score.
98. Allocate hostel room based on class, marks & conduct.
99. Decide promotion of student based on 5 subject marks (all >= 40 or any <40).
100. Evaluate complex nested condition:
Given marks, attendance, project score → print:
“Excellent”, “Good”, “Average”, “Fail”.

📘 25 ULTRA-HARD IF–ELSE PROGRAMS


(No Loop Allowed)
Only IF–ELSE, extreme logical thinking required

1. Check if four numbers can form the sides of a quadrilateral (sum of any 3 sides > 4th).

2. Given three points (x1, y1), (x2, y2), (x3, y3), check if all three lie in a straight line (slope
check, avoid division by zero).

3. Validate a 24-hour time (HH:MM:SS), handle edge cases like 23:59:60 (leap second).

**4. Check if a 4-digit number is a "super palindrome":

number = reverse(number) AND sum(first two digits) = sum(last two digits).**


**5. Check if a 5-digit number is mirror-symmetric:

digit1 = digit5 and digit2 = digit4, AND middle digit is even.**


**6. Given three angles, determine:

– valid triangle
– type (acute / right / obtuse)
– AND sides relationship (if given)
(All 3 checks through nested IF.)**
**7. Determine if a student gets a scholarship based on:

marks, attendance, income certificate, behaviour score, extra-curricular score (all combined
logic).**
**8. Validate a password using only IF–ELSE (no loops):

• length ≥ 8
• first char uppercase
• last char digit
• contains '@' in middle region.**
**9. Check if a date (DD/MM/YYYY) matches the company’s fiscal year rule:

Fiscal year starts April 1 of current year → March 31 of next year.**


10. Determine if a point (x, y) lies inside a rotated square (45° rotation) centered at origin using
only IF–ELSE.

11. Check if three numbers can be sides of a triangle AND whether triangle is golden ratio
triangle (longest/shortest ≈ 1.618 within tolerance).

**12. Given a 4-digit number ABCD, check advanced conditions:

A + C = B + D AND |AC − BD| < 5 AND last digit even.**


13. Detect if two time periods (start1–end1 and start2–end2) overlap, without using AND/OR
short circuit incorrectly.

**14. Detect whether a 6-character string is a valid hexadecimal code:

starts with # and remaining characters are 0–9 or A–F. (No loops: use charAt and nested
IF.)**
15. Determine if a complex number (a + bi) lies in any exact quadrant or lies exactly on angle
45°, 90°, 135°, etc.

**16. Classify an email address as:

Gmail / Yahoo / Outlook / Invalid (check @ and domain rules manually).**


**17. Check bank loan eligibility based on five parameters:

credit score, age, account balance, employment type, number of existing loans.**
**18. Determine if a 5-digit number is a “Kaprekar-like” number without breaking into
strings.

(d² split into left + right = original number).**


**19. Identify type of mobile number:

Starts with 6–9, 10 digits, last digit cannot repeat with first digit.**
**20. Given three temperatures of three cities, determine:

• hottest
• coldest
• median
• AND check if temperature difference > 20 for heatwave.**
**21. Check if a given (x, y) represents:

inside rectangle A OR circle B OR exactly on boundary of either.**


**22. Validate a name with complex rules (no loops):

• first character uppercase


• total length 3–30
• no digits allowed
• last character not space
• contains at least one lowercase letter.**
**23. Determine if a 3-digit number ABC satisfies:

A² + B² = C² OR
B² + C² = A² OR
A² + C² = B²
(meaning digits form a Pythagoras triplet in some order).**
**24. Evaluate inheritance category of a student:

Sports quota, Merit quota, Management quota, or Disqualified


based on:
marks, sports score, income, special certificates.**
**25. Given three boolean conditions A, B, C, evaluate:

Complex logical result:


Output “TRUE” only if exactly two out of A, B, C are true,
else “FALSE” — but WITHOUT using logical XOR (only nested IF).**
Here are 100 MCQs on Iterative Constructs in Java — ONLY QUESTIONS, NO BOLD
TEXT, clean structure, well-formatted.
(Options in the SAME LINE as requested.)

1. Which of the following is not an iterative statement in Java?


A) for B) while C) do-while D) goto
2. A loop that always executes at least once is:
A) for B) while C) do-while D) foreach
3. The condition in a while loop is checked:
A) before execution B) after execution C) only once D) randomly
4. The loop that checks condition at the bottom is:
A) for B) while C) do-while D) none
5. Which loop is preferred when the number of iterations is known?
A) for B) while C) do-while D) switch
6. Statements inside a loop are called:
A) body B) condition C) update D) initializer
7. The update part of a for loop executes:
A) before body B) after body C) before initialization D) before condition
8. A loop becomes infinite if:
A) condition always true B) condition always false C) update missing D) both A and
C
9. A loop inside another loop is called:
A) twin loop B) nested loop C) double loop D) sub loop
10. Statement used to exit a loop immediately is:
A) continue B) return C) break D) exit
11. Statement used to skip current iteration is:
A) skip B) break C) continue D) pass
12. Loop control variable means:
A) variable inside body B) variable in condition C) constant value D) output variable
13. The loop that executes minimum once:
A) while B) for C) do-while D) nested
14. For loop contains how many parts?
A) one B) two C) three D) four
15. The while loop is:
A) entry controlled B) exit controlled C) both D) none
16. The do-while loop is:
A) entry controlled B) exit controlled C) conditional D) static
17. Which loop is most suitable for menu-driven programs?
A) for B) while C) do-while D) switch
18. A loop that never stops is called:
A) dead loop B) broken loop C) infinite loop D) skip loop
19. Which of the following can cause an infinite loop?
A) wrong condition B) no increment C) faulty logic D) all
20. In for(int i=5; i>=1; i--), loop runs:
A) 4 times B) 5 times C) 6 times D) infinite
21. Loop used for traversing arrays:
A) for B) while C) do-while D) if
22. Loop terminating condition should be:
A) always true B) always false C) correct Boolean expression D) none
23. In while loop, initialization must be done:
A) inside body B) before loop C) after loop D) anywhere
24. In do-while loop, semicolon is placed:
A) before while B) after while condition C) after brace D) no semicolon needed
25. for(;;) represents:
A) error B) single execution C) infinite loop D) null loop
26. A loop that never executes:
A) for B) while C) do-while D) empty loop
27. In a for loop, initialization executes:
A) once B) twice C) always D) never
28. continue affects:
A) current iteration B) next iteration C) previous iteration D) loop end
29. break affects:
A) inner loop only B) outer loop only C) both A and B depending on location D) none
30. A nested loop means:
A) loop before loop B) loop after loop C) loop inside loop D) none
31. Which loop can be converted into while easily?
A) for B) do-while C) nested D) switch
32. If update expression is missing, loop may become:
A) finite B) infinite C) invalid D) skipped
33. A counter variable is used to:
A) count iterations B) store input C) store output D) none
34. A sentinel-controlled loop ends when:
A) limit reached B) specific value entered C) input ends D) error occurs
35. A flag variable stores:
A) number B) Boolean state C) string D) loop index
36. The for-each loop mainly works with:
A) arrays B) characters C) integers D) bits
37. The condition in a for loop must be:
A) integer B) Boolean C) float D) string
38. while(true) is used to create:
A) conditional loop B) infinite loop C) do-while loop D) flag loop
39. A loop without body is:
A) error B) allowed C) impossible D) none
40. A loop with empty condition generates:
A) compile error B) infinite loop C) terminate instantly D) none
41. In while loop, execution stops when condition is:
A) true B) false C) zero D) none
42. In do-while, body executes:
A) only when true B) only when false C) always once D) never
43. Converting for to while requires:
A) moving initialization B) moving update C) moving condition D) all
44. The increment part of for loop executes:
A) before condition B) before body C) after body D) only once
45. Loop can be used to generate:
A) series B) patterns C) repeated output D) all
46. Exit-controlled loop means checking condition:
A) first B) last C) both D) none
47. break exits from:
A) entire program B) nearest loop C) all loops D) switch only
48. continue sends control to:
A) update part B) condition part C) next iteration D) all
49. Loop ends when:
A) condition false B) break used C) error occurs D) all
50. Most flexible loop is:
A) for B) while C) do-while D) if
51. Nested loop complexity is measured by:
A) addition B) multiplication C) division D) subtraction
52. A loop that repeats fixed number of times:
A) definite loop B) indefinite C) sentinel D) flag loop
53. Loop controlling is:
A) modification of variable B) updating condition C) repeating instructions D) all
54. while loop best suits:
A) unknown repetitions B) known repetitions C) no repetition D) none
55. for loop best suits:
A) unknown repetitions B) known repetitions C) Boolean logic D) strings
56. Using two counters in one for loop is:
A) invalid B) valid C) dangerous D) impossible
57. Nested loop ends when:
A) inner false B) outer false C) both false D) any false
58. Which loop may use multiple expressions in update part?
A) for B) while C) do-while D) switch
59. A loop may also run in:
A) reverse order B) forward C) both D) none
60. Using break inside nested loop exits:
A) inner loop B) outer loop C) all loops D) none
61. while loop must have:
A) Boolean condition B) numeric condition C) string D) none
62. Infinite loop is used in:
A) games B) servers C) event programs D) all
63. for loop without condition is:
A) infinite B) compile error C) do-while D) empty
64. Condition part of for loop may be:
A) empty B) Boolean C) expression D) all
65. Missing update causes:
A) slow loop B) infinite loop C) fast loop D) skip loop
66. Using return in loop exits:
A) loop B) method C) program D) switch
67. Nested loop used for:
A) tables B) matrices C) patterns D) all
68. The block inside loop is defined with:
A) {} B) () C) [] D) none
69. For loop can be used without braces when:
A) one statement B) two statements C) three statements D) none
70. break inside switch exits:
A) loop B) switch C) both D) none
71. for loop with i+=2 increments:
A) double step B) half step C) no step D) random step
72. Which loop is commonly used for validation?
A) while B) for C) do-while D) nested
73. Loop initializing part can contain:
A) variable declaration B) assignment C) both D) none
74. for loop index variable stores:
A) constant B) varying values C) double only D) string only
75. for loop terminates when:
A) condition false B) break used C) return used D) all
76. Loop tests condition:
A) repeatedly B) once C) twice D) thrice
77. Using multiple conditions inside for loop is:
A) not allowed B) allowed with commas C) allowed using Boolean operators D) both
B and C
78. while loop begins with:
A) initialization B) condition C) update D) break
79. do-while ends with:
A) ; B) . C) : D) no symbol
80. Loop variable should be updated:
A) at start B) at end C) at right place D) anywhere
81. Boolean expression returns:
A) true/false B) 1/0 C) string D) number
82. break cannot be used in:
A) for B) while C) do-while D) if
83. continue cannot be used in:
A) for B) while C) do-while D) switch
84. while(true) is commonly used for:
A) exit early B) infinite loop C) break testing D) none
85. Loop body runs until:
A) condition false B) break C) return D) all
86. Loop variable should change:
A) manually B) automatically C) through update D) none
87. Nested loops run:
A) slow B) fast C) many iterations D) few iterations
88. Missing braces in loop affects:
A) only one statement B) all statements C) no statements D) skip
89. Update expression inside loop body:
A) may work B) may cause error C) same output D) better option
90. Loop can iterate on:
A) numbers B) characters C) arrays D) all
91. Using break in infinite loop:
A) helps exit B) creates error C) repeats D) none
92. for loop allows:
A) decrement B) increment C) multiplication updates D) all
93. Loop without update:
A) error B) infinite C) skip D) break
94. while loop condition cannot be:
A) true B) false C) string D) boolean
95. Nested loop complexity grows:
A) linearly B) polynomial C) constant D) zero
96. A loop printing numbers backward uses:
A) increment B) decrement C) skip D) continue
97. do-while loop is useful when:
A) input must run once B) condition unknown C) exit at last D) all
98. continue inside while sends control to:
A) condition B) update C) break D) next loop
99. Loop variable must be:
A) initialized B) declared C) updated D) all
100. Loop executes until:
A) condition fails B) break occurs C) return occurs D) all
Here are 50 Fill-in-the-Blanks questions on Iterative Constructs in Java (Class 9/10
ICSE).
Well-structured, no bold, clean formatting.

1. The loop that checks the condition before execution is __________.


2. The loop that executes at least once is __________.
3. The three parts of a for loop are initialization, condition, and __________.
4. A loop inside another loop is known as a __________ loop.
5. The keyword used to exit from a loop is __________.
6. The keyword used to skip the current iteration is __________.
7. A loop can become __________ if the condition never becomes false.
8. In a while loop, the condition must be a __________ expression.
9. The loop that checks condition at the bottom is __________.
10. In a for loop, initialization executes __________ time(s).
11. A loop which runs zero or more times is __________ controlled.
12. A loop which runs at least one time is __________ controlled.
13. The variable used in the condition part of a loop is called __________ variable.
14. A loop that never stops running is called __________ loop.
15. The update expression in a for loop executes __________ the loop body.
16. The do-while loop ends with a __________.
17. In a nested loop, __________ loop executes completely for each iteration of the outer
loop.
18. Missing update part in a loop can cause __________ loop.
19. The loop used when the number of repetitions is known is __________ loop.
20. The loop used when the number of repetitions is unknown is __________ loop.
21. break statement causes immediate __________ from the loop.
22. continue statement causes skipping of the __________ of the loop.
23. Infinite loops are written using the condition __________.
24. The while loop is an __________ controlled loop.
25. The do-while loop is an __________ controlled loop.
26. for(;;) in Java creates an __________ loop.
27. A __________ controlled loop stops when a special value is entered.
28. A __________ loop is used to repeat a block of statements.
29. The block of statements inside a loop is called the __________.
30. In while loop, initialization must be done __________ the loop.
31. A loop without braces will execute only __________ statement.
32. In a for loop, multiple variables can be initialized using __________.
33. continue transfers control back to the __________ part of the for loop.
34. break statement stops only the __________ loop in nested loops.
35. Nested loops increase time __________.
36. The update part of the for loop may contain __________ expressions.
37. A loop that executes a fixed number of times is a __________ loop.
38. A loop that ends when a specific condition becomes false is a __________ loop.
39. The statement for repeating tasks in Java is called a __________.
40. A loop that executes backward uses the __________ operator.
41. for-each loop is mainly used for iterating over __________.
42. A loop which checks condition before executing body is called __________ loop.
43. In a for loop, the condition must evaluate to __________.
44. continue always jumps to the __________ of the loop.
45. break is often used to terminate a loop __________.
46. A Boolean expression returns either __________ or __________.
47. A while loop stops executing when its condition becomes __________.
48. In do-while loop, the condition is written __________ the body.
49. The final value of a loop variable depends on the __________ expression.
50. A variable used for counting loop iterations is called a __________.
HARD LEVEL — 100 QUESTIONS

1. Find the output:


class Test {
public static void main(String[] args) {
int x = 5;
for(int i=1;i<=5;i++){
x += i;
[Link](x - i);
}
}
}

2. How many times will the loop run?


for(int i=100;i>0;i-=7){
[Link](i);
}

3. Find the output:


int a = 1;
for(int i=5;i>0;i--){
a *= i;
[Link](a);
}

4. Loop execution count?


for(int i=3;i<=90;i=i*2){
[Link](i);
}

5. Output?
int s = 0;
for(int i=1;i<10;i++){
s = s + (i%4);
[Link](s);
}

6. Loop count:
for(int i=50;i>=1;i/=2){
[Link](i);
}

7. Output:
int a = 2;
for(int i=1;i<=6;i++){
a = a * i - 1;
[Link](a);
}

8. How many iterations?


for(int i=-5;i<20;i+=5){
[Link](i);
}

9. Output:
int x = 10;
for(int i=1;i<=5;i++){
x = x - (i*i);
[Link](x);
}
10. Loop count?
for(int i=1;i<500;i=i*3){
[Link](i);
}

11.
int y = 1;
for(int i=10;i>=2;i-=2){
y += i/2;
[Link](y);
}

12.
for(int i=1;i<=15;i++){
[Link](i%5 + i/3);
}

13.
int x = 3;
for(int i=4;i>0;i--){
x = x * i;
[Link](x/i);
}

14.
for(int i=100;i>1;i/=3){
[Link](i - (i%3));
}

15.
int a = 1;
for(int i=2;i<=8;i++){
a = a + (a*i);
[Link](a);
}

16.
for(int i=7;i<=70;i+=7){
[Link](i/7 + i%3);
}

17.
int x = 20;
for(int i=1;i<=5;i++){
x -= (i*3);
[Link](x+i);
}

18.
for(int i=-10;i<=10;i+=4){
[Link](i*i - 3*i);
}

19.
int n = 0;
for(int i=1;i<=6;i++){
n = (n+i)%4;
[Link](n);
}

20.
for(int i=81;i>=1;i/=3){
[Link](i/2);
}

21.
int a = 5;
for(int i=1;i<7;i++){
a = a + (i%2==0 ? i : -i);
[Link](a);
}

22.
for(int i=4;i<=28;i+=4){
[Link]((i/4)*(i%5));
}

23.
int x = 2;
for(int i=3;i<=9;i++){
x = x*i - i;
[Link](x);
}

24.
for(int i=1;i<=7;i++){
[Link]((i*i) - (i*2));
}

25.
int a = 8;
for(int i=2;i<=6;i++){
a /= i - 1;
[Link](a+i);
}

26.
for(int i=50;i>=5;i-=5){
[Link]((i/5)*(i/10));
}

27.
int s = 2;
for(int i=1;i<=6;i++){
s = s + (i%3==0 ? -i : i*2);
[Link](s);
}

28.
for(int i=5;i<=45;i+=5){
[Link](i%7 + i/5);
}

29.
int x = 1;
for(int i=1;i<=8;i++){
x = (x+i)%5;
[Link](x);
}

30.
for(int i=3;i<50;i=i*2){
[Link](i - 3);
}
31.
int y = 10;
for(int i=1;i<=5;i++){
y = y/i + i;
[Link](y);
}

32.
for(int i=90;i>0;i-=9){
[Link](i/3 - i%4);
}

33.
int a = 4;
for(int i=2;i<=10;i+=2){
a = a*i - 2;
[Link](a);
}

34.
for(int i=1;i<=12;i++){
[Link]((i%4)*(i%3));
}

35.
int x = 100;
for(int i=5;i>=1;i--){
x -= (i*i);
[Link](x);
}

36.
for(int i=8;i<60;i+=8){
[Link](i/4 + i%6);
}

37.
int a = 7;
for(int i=1;i<=6;i++){
a = a + i - (i%2);
[Link](a);
}

38.
for(int i=1;i<=6;i++){
[Link]((i*i*i)%7);
}

39.
int x = 3;
for(int i=2;i<=6;i++){
x = x*i - (i%3);
[Link](x);
}

40.
for(int i=25;i>=5;i-=5){
[Link](i/5+i%3);
}

41.
int n = 0;
for(int i=1;i<=10;i++){
n += i%4;
[Link](n);
}

42.
for(int i=13;i<=65;i+=13){
[Link](i/13 - i%5);
}

43.
int x = 2;
for(int i=4;i>=1;i--){
x = x + (x*i);
[Link](x);
}

44.
for(int i=2;i<=12;i+=2){
[Link]((i*i)/4 - i%3);
}

45.
int a = 9;
for(int i=1;i<=7;i++){
a = (a+i)%6;
[Link](a);
}

46.
for(int i=100;i>10;i-=10){
[Link](i/10 + i%7);
}

47.
int x = 1;
for(int i=2;i<=7;i++){
x *= (i%4);
[Link](x);
}

48.
for(int i=3;i<=21;i+=3){
[Link]((i/3)*(i%4));
}

49.
int n = 5;
for(int i=1;i<=6;i++){
n = n - (i%3) + (i/2);
[Link](n);
}

50.
for(int i=15;i>0;i-=3){
[Link](i%5 + i/3);
}

51.
int s = 0;
for(int i=1;i<=7;i++){
s = s + (i*i)%4;
[Link](s);
}

52.
for(int i=2;i<=10;i+=2){
[Link]((i/2)*(i/4));
}

53.
int x = 12;
for(int i=3;i>=1;i--){
x = x/i + i;
[Link](x);
}

54.
for(int i=11;i<=55;i+=11){
[Link](i/5 + i%6);
}

55.
int a = 3;
for(int i=1;i<=8;i++){
a = (a*i)%7;
[Link](a);
}

56.
for(int i=100;i>=20;i-=20){
[Link](i%6 + i/10);
}

57.
int x = 5;
for(int i=2;i<=6;i++){
x = x*(i%3) - i;
[Link](x);
}

58.
for(int i=9;i>0;i--){
[Link](i%4 - i/3);
}

59.
int n = 1;
for(int i=1;i<=7;i++){
n = (n+i*i)%6;
[Link](n);
}

60.
for(int i=6;i<=30;i+=6){
[Link](i%8 + i/3);
}

61.
int a = 15;
for(int i=1;i<=5;i++){
a = a - (i%2) + (i*i);
[Link](a);
}
62.
for(int i=10;i>=2;i-=2){
[Link]((i/2)*(i%3));
}

63.
int x = 2;
for(int i=2;i<=8;i++){
x = (x+i)%5;
[Link](x);
}

64.
for(int i=4;i<=20;i+=4){
[Link](i/5 + i%4);
}

65.
int a = 6;
for(int i=3;i>=1;i--){
a = a*i - (i%2);
[Link](a);
}

66.
for(int i=7;i<50;i+=7){
[Link](i%9 + i/7);
}

67.
int x = 9;
for(int i=1;i<=6;i++){
x = x - i + (i%3);
[Link](x);
}

68.
for(int i=3;i<=15;i+=3){
[Link](i*i - i/3);
}

69.
int n = 4;
for(int i=1;i<=6;i++){
n = n + (i%2==0 ? i : -i);
[Link](n);
}

70.
for(int i=12;i>=3;i-=3){
[Link](i/2 + i%5);
}

71.
int a = 1;
for(int i=2;i<=9;i++){
a = (a+i)%4;
[Link](a);
}

72.
for(int i=2;i<=14;i+=2){
[Link]((i%5)*(i/2));
}

73.
int x = 7;
for(int i=1;i<=6;i++){
x = x/(i%3+1);
[Link](x+i);
}

74.
for(int i=9;i<=27;i+=9){
[Link](i/3 - i%4);
}

75.
int a = 10;
for(int i=1;i<=6;i++){
a = a - i/2 + i%3;
[Link](a);
}

76.
for(int i=5;i<=35;i+=5){
[Link](i/7 + i%6);
}

77.
int x = 1;
for(int i=2;i<=8;i++){
x = x + (i*i)%3;
[Link](x);
}

78.
for(int i=18;i>=3;i-=3){
[Link](i/3 - i%5);
}

79.
int n = 2;
for(int i=1;i<=8;i++){
n = (n*i)%5;
[Link](n);
}

80.
for(int i=4;i<=16;i+=4){
[Link](i/2 + i%7);
}

81.
int a = 5;
for(int i=1;i<=7;i++){
a = a + (i/2) - (i%4);
[Link](a);
}

82.
for(int i=10;i>0;i-=2){
[Link](i*i - i/2);
}
83.
int x = 14;
for(int i=1;i<=7;i++){
x = x - (i*i)%4;
[Link](x);
}

84.
for(int i=2;i<=18;i+=2){
[Link](i%7 + i/3);
}

85.
int n = 3;
for(int i=2;i<=8;i++){
n = n + ((i%3)*2);
[Link](n);
}

86.
for(int i=21;i>=7;i-=7){
[Link](i/3 + i%4);
}

87.
int a = 12;
for(int i=1;i<=5;i++){
a = a/i + (i%2);
[Link](a);
}

88.
for(int i=6;i<=36;i+=6){
[Link](i/3 - i%2);
}

89.
int x = 3;
for(int i=1;i<=7;i++){
x = (x+i)%6;
[Link](x);
}

90.
for(int i=8;i>=2;i-=2){
[Link]((i%3)*(i/2));
}

91.
int n = 11;
for(int i=1;i<=7;i++){
n = n - (i%3) + (i/3);
[Link](n);
}

92.
for(int i=9;i<=45;i+=9){
[Link](i%8 + i/9);
}

93.
int a = 2;
for(int i=1;i<=9;i++){
a = (a*i)%6;
[Link](a);
}

94.
for(int i=14;i>=2;i-=2){
[Link](i/4 + i%5);
}

95.
int x = 9;
for(int i=1;i<=8;i++){
x = x - (i%4);
[Link](x);
}

96.
for(int i=3;i<=27;i+=3){
[Link](i/5 + i%6);
}

97.
int n = 7;
for(int i=1;i<=6;i++){
n = n + i - (i%3);
[Link](n);
}

98.
for(int i=15;i>0;i-=3){
[Link](i*i - i%4);
}

99.
int a = 4;
for(int i=2;i<=10;i+=2){
a = a + (i/2) - (i%3);
[Link](a);
}

100.
for(int i=5;i<=25;i+=5){
[Link](i/6 + i%7);
}
50 THEORY QUESTIONS WITH ANSWERS (2 MARKS EACH)

1. What is an iterative construct in Java?


Ans: An iterative construct allows a set of statements to execute repeatedly until a
specified condition becomes false.
2. Name the three types of loops in Java.
Ans: The three loops are for loop, while loop, and do-while loop.
3. What is the difference between while and do-while loop?
Ans: In while, condition is checked before execution, but in do-while, the body
executes at least once before checking the condition.
4. When should a for loop be used?
Ans: When the number of iterations is known in advance, a for loop is preferred.
5. When should a while loop be used?
Ans: When the number of iterations is not known beforehand and depends on a
condition.
6. Define loop control variable.
Ans: A loop control variable is the variable whose value decides how long a loop will
run.
7. What is the purpose of the increment/decrement part in a for loop?
Ans: It updates the loop variable after each iteration to move the loop toward
termination.
8. Write the syntax of a for loop.
Ans: for(initialization; condition; update) { statements; }
9. Write the syntax of a while loop.
Ans: while(condition) { statements; }
10. Write the syntax of a do-while loop.
Ans: do { statements; } while(condition);
11. What happens if the loop condition is always true?
Ans: The loop becomes an infinite loop and executes endlessly.
12. What is an entry-controlled loop? Give an example.
Ans: A loop that checks its condition before executing the body. Example: for loop,
while loop.
13. What is an exit-controlled loop?
Ans: A loop that checks its condition after executing the body, e.g., do-while loop.
14. Define infinite loop.
Ans: A loop that never terminates because its condition always evaluates to true.
15. What is the purpose of break inside a loop?
Ans: It terminates the loop immediately.
16. What is the purpose of continue inside a loop?
Ans: It skips the current iteration and moves to the next one.
17. What is loop nesting?
Ans: Placing one loop inside another loop is called nested looping.
18. Can we omit any part of a for loop?
Ans: Yes, initialization, condition, and update can be omitted but semicolons must
remain.
19. What is a dry run?
Ans: Manually executing code step by step to trace values and output.
20. What will happen if loop update expression is missing?
Ans: If the variable never changes to meet the exit condition, the loop becomes
infinite.
21. What is loop counter?
Ans: A variable used to count and control the number of times a loop executes.
22. What is iteration?
Ans: One complete execution of the loop body.
23. Can a loop have multiple update expressions?
Ans: Yes, separated by commas inside the for loop.
24. What is the scope of loop variables declared inside the for loop?
Ans: They are local to the loop and cannot be accessed outside it.
25. Can we write a for loop without braces?
Ans: Yes, but only the first statement after the loop is considered inside the loop.
26. What is the use of the condition expression in a loop?
Ans: It decides whether the loop should continue or terminate.
27. What is an accumulator?
Ans: A variable used to store repetitive addition inside a loop (e.g., sum).
28. What is a counter variable?
Ans: A variable used to count how many times an event occurs.
29. What is the output of a loop with condition set to false initially?
Ans: The loop body does not execute, except in do-while.
30. Why is do-while loop useful for menu-driven programs?
Ans: Because it ensures the menu is displayed at least once.
31. What is meant by loop termination?
Ans: Finishing the loop when the condition becomes false.
32. Can we modify the loop variable inside the loop body?
Ans: Yes, but it may affect loop behavior and can cause unexpected results.
33. What is the importance of initialization in a loop?
Ans: It sets the starting value of the loop control variable.
34. What is meant by a step value in a loop?
Ans: The amount by which the loop variable changes after each iteration.
35. What is short-circuit evaluation in loop conditions?
Ans: When using logical operators (&&, ||), Java stops evaluating once the result is
determined.
36. Can we use floating-point variables in loops?
Ans: Yes, but it may lead to inaccuracies due to precision issues.
37. What is a counting loop?
Ans: A loop that increments or decrements a counter until a condition is met.
38. What is a sentinel-controlled loop?
Ans: A loop that terminates when a special value (sentinel) is encountered.
39. Define the term loop invariant.
Ans: A condition that remains true throughout every iteration of the loop.
40. What happens if the loop variable is not updated?
Ans: The loop may never terminate, leading to an infinite loop.
41. What is meant by loop reversal?
Ans: Running a loop backwards using decrement instead of increment.
42. What is the difference between i++ and ++i inside loops?
Ans: i++ increments after use; ++i increments before use. Both change i by 1.
43. What is a flag variable in loops?
Ans: A boolean variable used to indicate whether a certain condition was met during
looping.
44. Can break and continue be used together in the same loop?
Ans: Yes, but their roles differ; break exits the loop, continue skips to the next
iteration.
45. What is the use of multiple conditions in loops?
Ans: They help control loop execution based on more than one condition.
46. Why should we avoid modifying loop bounds inside the loop?
Ans: It can cause unexpected behavior, errors, or infinite loops.
47. What is a pre-test loop?
Ans: A loop that tests its condition before executing (for and while).
48. What is a post-test loop?
Ans: A loop that tests its condition after executing (do-while).
49. What is meant by trace table?
Ans: A table used to track variable values during each iteration.
50. Why are loops important in programming?
Ans: They reduce code repetition, improve efficiency, and handle repetitive tasks
automatically.
Here is the complete 100-program list divided into 4 levels:
Easy (1–25), Medium (26–50), Hard (51–75), Ultra Hard (76–100)
All programs must follow single-loop only rule.

EASY LEVEL (1–25)

1. Print numbers from 1 to 10.


2. Print numbers from 10 to 1.
3. Print even numbers from 1 to 20.
4. Print odd numbers from 1 to 20.
5. Print multiples of 5 up to 50.
6. Print first N natural numbers.
7. Print sum of first N natural numbers.
8. Print square of numbers from 1 to 10.
9. Print cube of numbers from 1 to 10.
10. Print table of a number using loop.
11. Count digits in a number.
12. Reverse a number.
13. Sum of digits of a number.
14. Product of digits of a number.
15. Count even digits in a number.
16. Count odd digits in a number.
17. Print all characters of a string.
18. Count vowels in a string.
19. Count consonants in a string.
20. Count digits in a string.
21. Reverse a string.
22. Count spaces in a string.
23. Sum of elements in an array.
24. Find maximum element in array.
25. Find minimum element in array.

MEDIUM LEVEL (26–50)

26. Count positive numbers in array.


27. Count negative numbers in array.
28. Count even numbers in array.
29. Count odd numbers in array.
30. Copy one array to another using loop.
31. Reverse an array using single loop.
32. Count frequency of a character in a string.
33. Remove spaces from a string using loop.
34. Convert string to uppercase manually.
35. Convert string to lowercase manually.
36. Replace vowels with * using loop.
37. Check if string is palindrome using loop.
38. Check if number is palindrome.
39. Check if number is Armstrong (single loop approach).
40. Check if number is perfect using loop.
41. Get all divisors of a number using loop.
42. Find sum of divisors of a number.
43. Count prime digits in a number.
44. Form a number by extracting digits from a string.
45. Check if a string contains only alphabets.
46. Remove all digits from string using loop.
47. Find the second largest digit in a number.
48. Find the second smallest digit in a number.
49. Check if digits of number are in increasing order.
50. Check if digits of number are in decreasing order.

HARD LEVEL (51–75)

51. Rotate digits of a number left by one place.


52. Rotate digits of a number right by one place.
53. Convert decimal to binary using loop.
54. Convert binary to decimal using loop.
55. Convert decimal to octal using loop.
56. Convert octal to decimal using loop.
57. Remove duplicate digits from a number (keep first occurrences).
58. Count digit transitions (changes from one digit to next).
59. Check if number is Armstrong for any length (single loop).
60. Check if number is Duck number.
61. Check if number is Spy number.
62. Check if number is Harshad number.
63. Find maximum repeating character in a string.
64. Find longest run of identical characters.
65. Remove repeated consecutive characters (aaabb → ab).
66. Count punctuation characters in a string.
67. Remove punctuation characters using loop.
68. Evaluate simple numeric expression with + only.
69. Evaluate numeric expression with + and – only.
70. Validate if string is binary (only 0 and 1).
71. Replace digits of string with next digit (9 → 0).
72. Remove all vowels from string.
73. Count alphanumeric characters.
74. Split string into even-index and odd-index characters.
75. Alternate sum of digits of a number (d1 - d2 + d3…).

ULTRA HARD LEVEL (76–100)

76. Find longest vowel sequence in string.


77. Find longest consonant sequence in string.
78. Reverse only vowels in string using one loop + two pointers.
79. Check if two strings are anagram using frequency + loop.
80. Roman numeral to decimal using one loop.
81. Decimal to Roman numeral using one loop.
82. Reduce fraction string "12/36" to lowest terms using loop for gcd.
83. Check if number is strobogrammatic.
84. Generate Collatz sequence until reaches 1 (single loop).
85. Check if number is happy number.
86. Convert number to base-5 using loop.
87. Convert base-5 to decimal using loop.
88. Check if string is isogram (no repeating characters).
89. Replace each character with next ASCII character (encryption).
90. Replace each character with previous ASCII (decryption).
91. Find first repeating element in array using boolean visited[] and loop.
92. Find smallest prime divisor of a number using loop.
93. Find largest prime divisor using loop.
94. Remove all prime digits from number.
95. Remove all composite digits from number.
96. Shift zeros to the end of number (digit rearrangement).
97. Generate series where next term = prev term + sum of digits (20 terms).
98. Convert long number to Indian comma format (12,34,567).
99. Find longest increasing digit chain inside number.
100. Implement run-length encoding (RLE) using a single loop.
JAVA QUESTION PAPER – EASY LEVEL
(50 Marks)
Topic: Single Loop Only

Section A – Theory (10 Marks)

(Attempt all questions. Each question 2 marks.)

1. What is a loop in Java? Give one simple example.


2. Write any two differences between for loop and while loop.
3. What is the purpose of the break statement? Write its syntax.
4. What is the role of the increment/decrement part in a loop?
5. Why is a single loop used in Java? Mention one advantage.

Section B – MCQ (10 Marks)

(Each question 1 mark. Choose the correct option.)

6. Which loop is commonly used when the number of iterations is known?


A) forB) whileC) do-whileD) switch
7. Loop variable is also known as:
A) keywordB) counterC) operatorD) object
8. Which symbol is used for increment?
A) --B) ++C) **D) &&
9. The loop stops when condition becomes:
A) trueB) falseC) zeroD) none
10. A loop that never ends is called:
A) empty loopB) nested loopC) infinite loopD) null loop
11. The loop body is executed at least once in:
A) forB) whileC) do-whileD) if
12. Variable inside loop is called:
A) local variableB) global variableC) static variableD) final variable
13. The starting value inside loop is called:
A) initializationB) terminationC) run timeD) object creation
14. To skip one step in a loop we use:
A) breakB) exitC) continueD) jump
15. Loop runs from 1 to 5 → how many iterations?
A) 4B) 5C) 6D) 3

Section C – Short Program Questions (Single Loop Only) (30 Marks)

(Attempt all questions. Use only ONE loop in each program. Each question 6 marks.)

16. Write a Java program using a single loop to print numbers 1 to 10.
17. Write a Java program using a single loop to print the sum of first 5 natural
numbers.
18. Write a Java program using a single loop to print all even numbers between 1 and
20.
19. Write a Java program using a single loop to print the digits of a number.
Example: Input = 456 → Output = 4 5 6
20. Write a Java program using a single loop to print the multiplication table of 5.

JAVA QUESTION PAPER – MEDIUM


LEVEL (50 Marks)
Section A – Theory (10 Marks)

(Attempt all. Each 2 marks.)

1. Explain the working of a for loop with an example.


2. What is an infinite loop? Give one example using for/while.
3. What is the difference between break and continue?
4. Why should loop counters be initialized properly?
5. What is the use of a loop condition? What happens if it is always true?

Section B – MCQ (10 Marks)

(Each 1 mark. Choose correct option.)

6. Which part of the loop executes first in a for loop?


A) conditionB) incrementC) initializationD) body
7. The continue statement skips:
A) entire loopB) only next iteration
C) loop variableD) stops program
8. To reverse a number using a loop, which operator is needed?
A) %B) && C) ==D) ||
9. Loop executes until:
A) condition becomes trueB) condition becomes false
C) compiler stopsD) memory is full
10. How many times will this loop execute?
for(int i=1; i<5; i++)
A) 3B) 4C) 5D) 6
11. The loop variable must be:
A) a constantB) updatedC) always negativeD) a double only
12. Which loop is best for reading input repeatedly until a condition fails?
A) forB) whileC) do-whileD) switch
13. A loop inside another loop is called:
A) nested loopB) stacked loopC) joint loopD) inner loop
14. What is the output?
for(int i=5; i>=1; i--) [Link](i);
A) 12345B) 54321C) 11111D) Error
15. Continue statement is used to:
A) terminate the loop
B) skip one iteration
C) change loop type
D) print output
Section C – Medium-Level Programs (Single Loop Only) (30 Marks)

(Each 6 marks. Use only ONE loop for each question.)

16. Write a Java program using one loop to print the sum of all even numbers from 1 to
50.
17. Write a Java program using one loop to reverse a given number.
Example: Input = 1234 → Output = 4321
18. Write a Java program using one loop to count how many digits are in a number.
Example: Input = 50234 → Output = 5 digits
19. Write a Java program using one loop to calculate the factorial of a number.
Example: 5! = 120
20. Write a Java program using one loop to print the Fibonacci series up to N terms.
Example: N = 7 → Output: 0 1 1 2 3 5 8

JAVA QUESTION PAPER – HARD LEVEL


(50 Marks)
Section A – Theory (10 Marks)

(Attempt all. Each 2 marks.)

1. Explain how a single loop can be used to solve problems normally solved using
nested loops. Give an example.
2. What are loop invariants? Why are they important in algorithm design?
3. Describe the role of flags in loop-based logic. Give an example using a boolean flag.
4. How can you optimize loop performance in Java? Mention any two techniques.
5. Why is it dangerous to modify the loop counter inside the loop body? Explain with an
example.

Section B – MCQ (10 Marks)

(Each 1 mark. Choose the correct option.)

6. What will happen if the loop counter is updated incorrectly?


A) Proper outputB) Infinite loopC) Faster programD) Syntax error
7. Which of the following can replace a nested loop with a single loop?
A) ArraysB) Mathematical formulas
C) ObjectsD) Interfaces
8. The time complexity of a single loop is generally:
A) O(1)B) O(n)C) O(n²)D) O(log n)
9. A loop is best optimized when:
A) Condition is simpleB) Printing is inside loop
C) Many breaks usedD) Variable declared repeatedly
10. What is the output of the following?
11. int x = 0;
12. for(int i=1; i<=5; i++) x = x + i*i;
13. [Link](x);

A) 20B) 30C) 55D) 50


14. A loop can simulate nested loops by:
A) using counters smartly
B) using recursion
C) using arrays
D) using exceptions
15. A loop that solves multiple tasks inside one iteration is called:
A) multi-loopB) multipurpose loop
C) overloaded loopD) nested loop
16. What is the output?
17. for(int i=10; i>0; i-=3)
18. [Link](i+" ");

A) 10 7 4 1B) 10 8 6 4 2C) 10 7 5 2D) Error

19. Which approach is best for generating patterns using one loop?
A) String concatenation
B) Mathematical indexing
C) Nested loops
D) File handling
20. A single loop can generate prime numbers using:
A) flag variablesB) switch case
C) bitwise operatorsD) StringBuffer

Section C – Hard-Level Programs (Single Loop Only) (30 Marks)

(Each 6 marks. Use only ONE loop per program.)

16. Write a Java program using one loop to print all prime numbers between 1 and 100.
(Hint: Use flags, no nested loops.)
17. Write a Java program using one loop to check whether a number is Armstrong or
not.
Example: 153 → 1³ + 5³ + 3³ = 153
18. Write a Java program using one loop to print a right-angled triangle pattern like:
*
**
***
****

(Use string concatenation inside a single loop.)

19. Write a Java program using one loop to find the GCD (Greatest Common Divisor)
of two numbers.
20. Write a Java program using one loop to separate digits of a number and print the sum
of even digits and sum of odd digits.
Example: Input = 54823 → Even sum = 12, Odd sum = 11

CLASS 9 ICSE – JAVA QUESTION PAPER


(SET–1) (50 Marks)
Syllabus Covered:

✔Variables & Data Types


✔Operators
✔if–else
✔Loops (single loop)
✔Basic Mathematical Programs
✔Simple Patterns (allowed in Class 9)
❌ No arrays, no functions, no objects (as per Class 9 rules)

SECTION A – THEORY (10 Marks)

(Attempt ALL. Each question 2 marks.)

1. What is the difference between entry-controlled and exit-controlled loops? Give one
example of each.
2. Explain conditional operator with a suitable example.
3. What is the purpose of the modulus % operator in loop-based programs?
4. Define increment and decrement operators with examples.
5. What is the importance of using braces in loop statements?

SECTION B – MCQ (10 Marks)

(Each 1 mark. Choose the correct option.)

6. In Java, which loop checks the condition before execution?


A) do-while B) for C) switch D) both A & B
7. The operator used to check equality is:
A) = B) == C) != D) <=
8. The range of int is:
A) -100 to 100 B) -32768 to 32767 C) depends on system D) none
9. The correct syntax of a for loop is:
A) for(i=1;i<10;i++)
B) for i=1 to 10
C) loop(i<10)
D) repeat(i++)
10. Output of:
11. int x = 7 % 3;
12. [Link](x);

A) 0 B) 1 C) 2 D) 3

13. A variable declared inside a loop is called:


A) global variable B) block variable C) class variable D) final variable
14. The operator used for logical AND is:
A) && B) || C) & D) ==
15. Which data type is used for decimal values?
A) int B) double C) char D) boolean
16. Which keyword is used to stop a loop suddenly?
A) stop B) exit C) break D) return
17. Java statements end with:
A) , B) ; C) : D) .

SECTION C – JAVA PROGRAMS (30 Marks)

(Each program carries 6 marks. Use only ONE LOOP wherever needed.)
All programs are within Class 9 ICSE syllabus.

16. Write a Java program to accept a number and print whether it is odd or even.
17. Write a Java program to print the sum of all numbers from 1 to 50 using a for loop.
18. Write a Java program to accept a number and print its multiplication table (1 to 10)
using a loop.
19. Write a Java program to accept a number and print the reverse of the number.
Example: 124 → 421
20. Write a Java program to display the following pattern using string concatenation
(allowed in Class 9):
1
12
123
1234

CLASS 9 ICSE – JAVA QUESTION PAPER


(HARD VERSION) – SET–2 (50 Marks)
SECTION A – THEORY (10 Marks)

(Each question 2 marks.)

1. Explain how the modulus operator (%) helps in solving number-based logic
problems. Give a suitable example.
2. What is the difference between while loop and do-while loop? Which one is entry-
controlled?
3. What is a loop counter? Why is correct initialization important?
4. Explain the concept of a sentinel value with an example.
5. What is the difference between simple if and if-else ladder? Give one valid use case
for each.

SECTION B – MCQs (10 Marks)

(Each 1 mark.)

6. What will be the output?


7. int x = 25;
8. [Link](x / 10);

A) 2 B) 5 C) 25 D) 0
9. Which operator is used to combine multiple conditions?
A) ++ B) && C) % D) =
10. Java’s char data type internally stores:
A) ASCII values B) Unicode values C) Hex codes D) Binary only
11. In a loop, i = i + 2 means:
A) skip 1 value B) skip 2 values C) skip alternate values D) both A & C
12. Output of:
13. int n = 8 % 5;
14. [Link](n);

A) 1 B) 2 C) 3 D) 8

15. break statement:


A) pauses loop
B) stops loop
C) skips iteration
D) repeats loop
16. Which is NOT a valid loop?
A) for B) while C) do-while D) repeat
17. Output of:
18. for(int i=10; i>=6; i--)
19. [Link](i+" ");

A) 10 9 8 7 6 B) 10 8 6 C) 9 7 5 D) 10 only

20. Logical NOT operator is:


A) ! B) != C) <> D) ~
21. A variable declared inside loop is:
A) global variable B) instance variable
C) local variable D) static variable

SECTION C – HARD JAVA PROGRAMS (30 Marks)

(6 marks each)
All questions must follow ICSE Class 9 rules: only loops, if-else, operators; NO arrays,
NO functions, NO advanced concepts.

16. Write a Java program to input a number and check if it is a Special Number.

A number is Special if:


Sum of factorials of its digits = original number
Example: 145 → 1! + 4! + 5! = 145
(Use single loop with repeated modulus and division operations.)

17. Write a Java program to find whether a number is a Pronic Number or not.

A Pronic number is the product of two consecutive numbers:


6=2×3
12 = 3 × 4
(Use one loop to check all possible pairs.)
18. Write a Java program to print all prime numbers between 1 and 200 using only ONE loop.

(Hint: Count the number of factors inside the same loop using temporary variables.)

19. Write a Java program to check whether a number is a Buzz Number or not.

Buzz Number:
– ends with 7 OR
– divisible by 7

(Use logical OR and one loop only if needed for digit processing.)

20. Write a Java program to display this pattern using only ONE loop and string concatenation:
*
**
****
********
100 MCQ ON NESTED FOR LOOPS (JAVA) – CLEAN CODE FORMAT

1. What is the total number of iterations?


for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
}
}

a) 3 b) 4 c) 7 d) 12

2. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
[Link]("*");
}
}

a) *** b) ****** c) ** d) ********

3. How many times does the outer loop run?


for (int i = 5; i > 0; i--) {
}

a) 4 b) 5 c) 6 d) Infinite

4. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
[Link](i + j + " ");
}
}

a) 2 3 3 4 b) 2 2 3 3 c) 3 4 4 5 d) 2 3 4 5

5. Number of times print() executes?


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
[Link]("#");
}
}

a) 6 b) 9 c) 3 d) 12

6. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
[Link]("*");
}
}

a) ** b) *** c) ****** d) * ** ***

7. How many outer iterations?


for (int i = 2; i <= 10; i += 2) {
}

a) 3 b) 4 c) 5 d) 6

8. Inner loop runs per outer loop?


for (int i = 0; i < 5; i++) {
for (int j = 10; j > 7; j--) {
}
}

a) 2 b) 3 c) 4 d) 5

9. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i);
}
}

a) 112233 b) 111222 c) 121212 d) 123123

10. How many * printed?


for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
[Link]("*");
}
}

a) 4 b) 6 c) 8 d) 10

11. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
[Link](j);
}
}

a) 121212 b) 112233 c) 123123 d) 221122

12. How many times is j-loop condition checked?


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
}
}

a) 9 b) 10 c) 12 d) 16

13. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 1; j < i; j++) {
[Link](j + " ");
}
}

a) 1 1 2 1 2 3 b) 1 1 2 3 c) 1 2 1 2 3 d) 2 3 4

14. How many iterations?


for (int i = 0; i < 4; i++) {
for (int j = i; j < 4; j++) {
}
}

a) 10 b) 8 c) 6 d) 4

15. Output?
for (int i = 3; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link]("*");
}
}

a) ****** b) ***** c) *** ** * d) *******

16. Value printed?


int c = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
c++;
}
}
[Link](c);

a) 3 b) 4 c) 5 d) 6

17. Output?
for (int i = 1; i <= 2; i++) {
for (int j = i; j <= 3; j++) {
[Link](j);
}
}

a) 12323 b) 234345 c) 123123 d) 2334

18. How many times executed?


for (int i = 5; i >= 3; i--) {
for (int j = 1; j <= 5; j += 2) {
}
}

a) 3 b) 6 c) 9 d) 15

19. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i * 2; j++) {
[Link]("#");
}
}

a) ###### b) # ## ### c) ####### d) ###### ####

20. Total iterations?


for (int i = 2; i <= 6; i += 2) {
for (int j = 0; j < 3; j++) {
}
}

a) 3 b) 6 c) 9 d) 12

21. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 4; j++) {
[Link](i + j + " ");
}
}
a) 2 3 4 5 b) 2 3 4 5 3 4 5 6 4 5 6 7 c) 1234 d) 2345 3456 4567

22. How many iterations?


for (int i = 0; i < 4; i++) {
for (int j = 0; j <= i; j++) {
}
}

a) 4 b) 6 c) 8 d) 10

23. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 1; j < i; j++) {
[Link](i);
}
}

a) 233444 b) 244444 c) 23344 d) 234

24. What is printed?


for (int i = 3; i >= 1; i--) {
for (int j = i; j >= 1; j--) {
[Link](j + " ");
}
}

a) 3 2 1 2 1 1 b) 3 2 1 3 2 1 c) 1 2 3 1 2 d) 3 3 3

25. Total count?


int c = 0;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 2; j++) {
c++;
}
}
[Link](c);

a) 6 b) 8 c) 4 d) 10

26. Output?
for (int i = 1; i <= 5; i += 2) {
for (int j = 1; j <= i; j++) {
[Link]("*");
}
}

a) ****** b) ***** c) * *** ***** d) ***

27. How many times j-loop executes?


for (int i = 1; i <= 3; i++) {
for (int j = 5; j >= 3; j--) {
}
}

a) 3 b) 6 c) 9 d) 12

28. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
[Link](j - i + " ");
}
}

a) 0 1 2 -1 0 1 b) 1 2 3 1 2 3 c) -1 0 1 -2 -1 0 d) 0 0 0

29. Total iterations?


for (int i = 10; i >= 6; i -= 2) {
for (int j = 1; j <= 4; j++) {
}
}

a) 4 b) 6 c) 8 d) 12

30. Output?
for (int i = 1; i <= 4; i++) {
for (int j = 4; j >= i; j--) {
[Link]("#");
}
}

a) #### ### ## # b) ########## c) ####### d) #### ##

31. Count?
int c = 0;
for (int i = 2; i <= 6; i += 2) {
for (int j = 1; j <= i; j++) {
c++;
}
}
[Link](c);

a) 12 b) 20 c) 9 d) 18

32. Output?
for (int i = 3; i <= 5; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i * j + " ");
}
}

a) 3 6 9 4 8 12 5 10 15 b) 3 4 5 6 7 8 c) 3 6 9 5 10 15 d) 1 2 3

33. Total inner executions?


for (int i = 1; i <= 5; i++) {
for (int j = i; j <= 5; j++) {
}
}

a) 10 b) 15 c) 20 d) 5

34. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 3; j >= i; j--) {
[Link](i + j + " ");
}
}

a) 4 5 6 4 5 4 b) 4 5 6 5 6 6 c) 4 5 6 4 5 d) 6 5 4

35. Value?
int sum = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
sum += i + j;
}
}
[Link](sum);

a) 12 b) 18 c) 24 d) 30

36. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
[Link](j * j + " ");
}
}

a) 1 4 1 4 9 1 4 9 16 b) 1 4 1 4 9 1 4 9 16 25 c) 4 9 16 d) none

37. Loop count?


for (int i = 5; i > 0; i--) {
for (int j = 1; j < 5; j++) {
}
}

a) 5 b) 20 c) 25 d) 30

38. Output?
for (int i = 1; i <= 4; i++) {
for (int j = i; j >= 1; j--) {
[Link](j + " ");
}
}

a) 1 2 1 3 2 1 4 3 2 1 b) 1 12 123 1234 c) 4 3 2 1 d) none

39. Total times printed?


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 4; j++) {
[Link]("*");
}
}

a) 4 b) 7 c) 12 d) 3

40. Output?
for (int i = 2; i <= 3; i++) {
for (int j = i; j <= 5; j++) {
[Link](i + j + " ");
}
}

a) 4 5 6 5 6 7 8 b) 4 5 6 7 5 6 7 8 9 c) 5 6 7 8 d) 4 5 6

41. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 2; j <= 4; j++) {
[Link](i * j + " ");
}
}
a) 2 3 4 4 6 8 6 9 12 b) 3 4 5 6 7 8 c) 2 4 6 8 10 12 d) 3 6 9

42. Total iterations?


for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
}
}

a) 10 b) 20 c) 25 d) 5

43. Output?
for (int i = 3; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link](j + " ");
}
}

a) 1 2 3 1 2 1 b) 3 2 1 2 1 1 c) 1 2 3 2 1 1 d) 3 3 3

44. Value of c?
int c = 0;
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 4; j++) {
c += i + j;
}
}
[Link](c);

a) 12 b) 16 c) 24 d) 20

45. Output?
for (int i = 1; i <= 4; i++) {
for (int j = i; j <= 4; j++) {
[Link]("*");
}
}

a) ******** b) **** *** ** * c) ****** d) *****

46. Count?
for (int i = 2; i <= 6; i += 2) {
for (int j = 2; j <= 6; j += 2) {
}
}

a) 4 b) 6 c) 9 d) 12

47. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 2; j <= 5; j++) {
[Link](j - i + " ");
}
}

a) 1 2 3 4 0 1 2 3 b) 1 2 3 4 1 2 3 4 c) 0 1 2 3 d) 4 3 2

48. Inner iterations?


for (int i = 1; i <= 4; i++) {
for (int j = 4; j >= i; j--) {
}
}

a) 10 b) 9 c) 6 d) 4

49. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
[Link](i * i + " ");
}
}

a) 4 4 9 9 9 16 16 16 16 b) 4 9 16 c) 4 9 16 25 d) 4 4 4

50. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 3; j >= 1; j--) {
[Link](i + j + " ");
}
}

a) 4 5 6 5 6 7 6 7 8 b) 4 5 6 4 5 6 4 5 6 c) 1 2 3 d) 3 3 3

51. Total iterations?


for (int i = 0; i < 6; i += 2) {
for (int j = 1; j <= 3; j++) {
}
}

a) 6 b) 9 c) 12 d) 18

52. Output?
for (int i = 3; i >= 1; i--) {
for (int j = i; j <= 3; j++) {
[Link](i + j + " ");
}
}

a) 6 5 4 5 4 3 4 3 2 b) 4 5 6 3 4 5 2 3 4 c) 6 5 4 6 5 4 6 5 4 d) 3 4 5

53. Count?
for (int i = 5; i >= 3; i--) {
for (int j = 1; j <= i; j++) {
}
}

a) 6 b) 9 c) 12 d) 15

54. Output?
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
[Link](j + i + " ");
}
}

a) 2 3 4 5 3 4 5 6 b) 2 3 4 5 4 5 6 7 6 7 8 9 c) 2 3 4 5 6 7 8 9 d) none

55. Total [Link] executions?


for (int i = 1; i < 5; i++) {
for (int j = 2; j < 7; j += 2) {
[Link]("*");
}
}

a) 10 b) 12 c) 8 d) 6

56. Output?
for (int i = 2; i <= 3; i++) {
for (int j = 1; j <= 4; j++) {
[Link](i - j + " ");
}
}

a) 1 0 -1 -2 2 1 0 -1 b) 1 1 1 1 c) -1 -2 -3 -4 d) 2 3 4 5

57. Total iterations?


for (int i = 7; i >= 1; i -= 2) {
for (int j = 1; j <= 3; j++) {
}
}

a) 3 b) 6 c) 9 d) 12

58. Output?
for (int i = 1; i <= 4; i++) {
for (int j = 4; j > i; j--) {
[Link]("*");
}
}

a) *** ** * b) ******* c) **** d) ***

59. Value?
int sum = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
sum += i - j;
}
}
[Link](sum);

a) 0 b) -3 c) -6 d) 3

60. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 2; j <= i; j++) {
[Link](i + j + " ");
}
}

a) 4 5 6 6 7 8 b) 4 5 6 6 7 8 8 9 10 c) 3 4 5 d) 4 4 4

✅Nested For Loop MCQs (60–100) —


Options Same Line
60. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
[Link](j);
}
[Link]();
}

A) 123 123 123 B) 1 / 12 / 123 C) 321 D) Error

61. Inner loop executes how many times?


for (int i = 0; i < 5; i++) {
for (int j = 0; j < 3; j++) { }
}

A) 3 B) 5 C) 15 D) 8

62. Output?
for (int i = 3; i > 0; i--) {
for (int j = 0; j < i; j++) {
[Link]("*");
}
[Link]();
}

A) *** ** * B) * ** *** C) No output D) Error

63. Output?
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
[Link](i + j + " ");
}
}

A) 0 1 1 2 B) 1 2 3 4 C) 00 11 D) Error

64. Total iterations?


for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
for (int c = 0; c < 2; c++) { }
}
}

A) 8 B) 16 C) 32 D) 64

65. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i * j + " ");
}
[Link]();
}

A) 1 2 3 / 2 4 6 B) 1 2 / 1 2 3 C) 1 4 9 D) Error
66. Output?
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) [Link]("#");
else [Link]("*");
}
[Link]();
}

A) ### ### ### B) #** # **# C) # # # D) Error

67. Shape printed?


for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
[Link]("*");
}
[Link]();
}

A) Square B) Right triangle C) Left triangle D) Inverted triangle

68. Output?
int sum = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
sum += i + j;
}
}
[Link](sum);

A) 6 B) 9 C) 12 D) 15

69. Last printed pair?


for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
[Link](i + " " + j);
}
}

A) 2 1 B) 3 2 C) 2 0 D) 1 2

70. Inner loop executes how many times?


for (int i = 0; i < 6; i++) {
for (int j = 0; j < i; j++) { }
}

A) 6 B) 10 C) 15 D) 20

71. Output?
for (int i = 1; i <= 3; i++) {
for (int j = i; j <= 3; j++) {
[Link]("*");
}
[Link]();
}
A) *** ** * B) * ** *** C) No output D) ******

72. Total digits printed?


for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
[Link](j);
}
}

A) 4 B) 7 C) 12 D) 3

73. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i - j + " ");
}
[Link]();
}

A) Subtraction grid B) Error C) Same row repeated D) Diagonal only

74. Output?
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {
[Link](i);
}
[Link]();
}

A) 0 / 11 / 222 B) 1 / 22 / 333 C) 0 / 10 / 210 D) No output

75. Output?
for (int i = 0; i < 2; i++) {
for (int j = i; j < 2; j++) {
[Link](j);
}
[Link]();
}

A) 012 / 12 B) 01 / 1 C) 012 / 01 D) 01 / 00

76. How many stars printed?


for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
[Link]("*");
}
}

A) 8 B) 12 C) 16 D) 4

77. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i + j);
}
}

A) 234345456 B) 123123123 C) 112233 D) 678

78. What pattern?


for (int i = 1; i <= 4; i++) {
for (int j = 4; j >= i; j--) {
[Link]("*");
}
[Link]();
}

A) Increasing B) Decreasing triangle C) Square D) Diamond

79. Output?
for (int i = 2; i >= 0; i--) {
for (int j = 0; j <= i; j++) {
[Link](j);
}
[Link]();
}

A) 012 / 01 / 0 B) 210 / 21 / 2 C) 012012 D) Error

80. Characters printed?


for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
[Link]("#");
}
}

A) 3 B) 6 C) 9 D) 12

81. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
[Link](i + j + " ");
}
[Link]();
}

A) 2 / 3 4 / 4 5 6 B) 1 / 12 / 123 C) 3 / 5 / 7 D) Error

82. Output?
for (int i = 0; i < 4; i++) {
for (int j = i; j < 4; j++) {
[Link]("*");
}
[Link]();
}

A) **** *** ** * B) * ** *** **** C) **** repeated D) Error


83. Last printed value?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i * j);
}
}

A) 6 B) 3 C) 2 D) 9

84. Output count?


for (int i = 0; i < 5; i++) {
for (int j = 0; j <= i; j++) { }
}

A) 10 B) 15 C) 20 D) 5

85. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= i; j++) {
[Link](j * j + " ");
}
[Link]();
}

A) 1 / 1 4 B) 1 / 4 9 C) 1 1 / 2 2 D) Error

86. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
[Link]((i * j) % 2);
}
[Link]();
}

A) 101 / 010 / 101 B) 111 / 222 / 333 C) 000 D) Error

87. Total prints?


for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 5; j++) {
[Link]("X");
}
}

A) 4 B) 5 C) 20 D) 10

88. Output?
for (int i = 0; i < 3; i++) {
for (int j = 2; j >= 0; j--) {
[Link](i + j);
}
}

A) 210321432 B) 012012012 C) 222 D) 543


89. Output?
for (int i = 2; i <= 4; i++) {
for (int j = 1; j <= 3; j++) {
[Link](i - j + " ");
}
[Link]();
}

A) 1 0 -1 / 2 1 0 / 3 2 1 B) 1 2 3 C) 0 0 0 D) Error

90. Output?
for (int i = 1; i <= 2; i++) {
for (int j = 2; j >= i; j--) {
[Link]("*");
}
[Link]();
}

A) ** * B) * ** C) *** ** * D) Error

91. Output?
for (int i = 3; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
[Link](j);
}
[Link]();
}

A) 123 / 12 / 1 B) 1 / 12 / 123 C) 321 / 21 / 1 D) Error

92. Last printed character?


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
[Link]("*");
}
}

A) * B) 3 C) 9 D) None

93. Output?
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
[Link](j * i + " ");
}
[Link]();
}

A) 0 0 0 0 / 0 1 2 3 B) 0 1 2 3 repeated C) 1 2 3 4 D) Error

94. Output?
for (int i = 1; i <= 4; i++) {
for (int j = 4; j > i; j--) {
[Link](j);
}
[Link]();
}
A) 432 / 43 / 4 / (blank) B) 1234 C) 444 D) Error

95. Output?
for (int i = 2; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
[Link]((i + j) % 3);
}
}

A) 0112 B) 1201 C) 12 D) 2222

96. Output?
for (int i = 0; i < 4; i++) {
for (int j = i; j >= 0; j--) {
[Link]("*");
}
[Link]();
}

A) * ** *** **** B) **** *** ** * C) **** repeated D) Error

97. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 3; j >= i; j--) {
[Link](i);
}
[Link]();
}

A) 111 / 22 / 3 B) 111 / 22 / 3 3 C) 1 / 22 / 333 D) Error

98. Output?
int c = 0;
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
c++;
}
}
[Link](c);

A) 3 B) 5 C) 6 D) 9

99. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3 - i; j++) {
[Link]("#");
}
[Link]();
}

A) ## / # / (blank) B) # / ## / ### C) ### / ## / # D) Error

100. Output?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i * 2; j++) {
[Link](j);
}
[Link]();
}

A) 12 / 1234 / 123456 B) 1 / 22 / 333 C) 123 / 1234 / 12345 D) Error


✅100 Java Programs on Nested Loops
(Categorized)
(Only program statements, no code — unless you want code also.)

✅ EASY LEVEL (1–25)


1. Print a 3×3 block of stars.
2. Print a right triangle of stars of 5 rows.
3. Print numbers 1 to 5 in each of 3 rows.
4. Print pattern:
1
12
123
5. Print pattern:
111
222
333
6. Print multiplication table of 1 to 5.
7. Print even numbers from 2 to 20 in 5 rows.
8. Print a square of numbers from 1 to n.
9. Print 5 rows of alphabets from A to E.
10. Print triangle of alphabets (A, AB, ABC...).
11. Print decreasing triangle of stars.
12. Print a hollow square of stars.
13. Print table of 5 using two loops.
14. Print sum of each row in a nested loop.
15. Print numbers from 1 to 9 in matrix form.
16. Print odd numbers pattern.
17. Print pattern with repeated row numbers.
18. Print pattern with repeated column numbers.
19. Print pattern:
*
**

***

20. Print reversed numeric triangle.


21. Print pattern: 1 2 3 / 1 2 3 / 1 2 3
22. Print star border rectangle.
23. Print alphabet rectangle (A B C...).
24. Print n rows of same word (Hello).
25. Print pattern: 10 9 8 / 7 6 5 / 4 3 2.

✅ MEDIUM LEVEL (26–50)


26. Print Floyd’s triangle.
27. Print Pascal’s half pyramid.
28. Print mirrored right triangle using spaces.
29. Print inverted mirrored right triangle.
30. Print hollow triangle.
31. Print diagonal line inside square.
32. Print X pattern using stars.
33. Print checkerboard pattern.
34. Print a numeric pyramid (1 12 123...).
35. Print a reverse numeric pyramid.
36. Print alphabet pyramid (A AB ABC...).
37. Print pattern of alternating 0 and 1.
38. Print pattern of prime numbers in rows.
39. Print pattern of factorials.
40. Print multiplication grid (1×1 to 5×5).
41. Print table for numbers 2 to 10.
42. Print a rhombus of stars using spaces.
43. Print increasing and decreasing star pattern (like diamond upper half).
44. Print patterns using ASCII values.
45. Print sum of diagonals of a number square.
46. Print frequency of digits using nested loops.
47. Print matrix values row-wise and column-wise.
48. Generate pattern of cubes of numbers.
49. Pattern of alphabets repeated by row count.
50. Pattern of alphabets repeated by column count.

✅ HARD LEVEL (51–75)


51. Print full diamond star pattern.
52. Print full number diamond pattern.
53. Generate spiral matrix (no arrays).
54. Print zig-zag number pattern.
55. Generate numeric hollow diamond.
56. Numeric palindromic pyramid.
57. Centered star pyramid (full pyramid).
58. Centered number pyramid.
59. Inverted centered pyramid.
60. Numeric hourglass pattern.
61. Star hourglass pattern.
62. Hollow pyramid.
63. Hollow inverted pyramid.
64. Print cross pattern inside a rectangle.
65. Alphabet diamond pattern.
66. Fibonacci pattern using nested loops.
67. Collatz-like number pattern.
68. Pattern with alternating rows of stars and numbers.
69. Generate multiplication tables in triangular structure.
70. Print pattern: each row contains squares of numbers.
71. Pattern showing prime numbers only in diagonal.
72. Pascal triangle (first 10 rows) using loops only.
73. Generate exponential pattern (powers of 2).
74. Print mirror-image patterns side by side.
75. Generate hourglass with numbers instead of stars.

✅ ULTRA HARD LEVEL (76–100)


(Very complex nested loop patterns good for ICSE competitive understanding)

76. Print full spiral matrix up to n×n using only nested loops (no arrays).
77. Print full symmetric diamond with dynamic height.
78. Print numeric butterfly pattern.
79. Generate star-based butterfly pattern.
80. Create hollow butterfly.
81. Create alphabet butterfly.
82. Print numeric swastik pattern (nested loops).
83. Print star swastik pattern.
84. Print concentric squares pattern (like layers).
85. Print concentric numeric squares.
86. Print target-like pattern (circles but squared).
87. Create a wave pattern of stars.
88. Create a sine-wave–like number pattern.
89. Print chessboard with alternating alphabets.
90. Diamond plus cross hybrid pattern.
91. Generate matrix where each row is left-rotated.
92. Generate matrix where each row is right-rotated.
93. Print pattern of prime numbers forming a triangle.
94. Palindromic double triangle joined together.
95. Full binary-tree like pyramid using numbers.
96. Full binary-tree like pyramid using stars.
97. Print expanding and contracting mirrored triangle.
98. Print Pascal triangle centered (full symmetric).
99. Generate 3D-looking cube pattern using stars.
100. Generate illusion pattern (multiple boxes inside each other).
JAVA QUESTION PAPER – EASY LEVEL
(Nested Loops) – 50 Marks
SECTION A – THEORY (10 Marks)

(Each question 2 marks. Attempt all.)

1. What is a nested loop? Give one simple example.


2. How many loops are required to print a rectangular pattern of rows and columns?
3. Mention one difference between single loop and nested loop.
4. Why is the inner loop executed more times than the outer loop?
5. Write the general syntax of a nested for loop in Java.

SECTION B – MCQ (10 Marks)

(Each 1 mark. Choose the correct option.)

6. A nested loop means:


A) loop inside a loop B) two programs C) two variables D) none
7. To print a star pattern, nested loops usually control:
A) rows & columns B) methods C) classes D) objects
8. In nested loops, which loop runs first?
A) inner B) outer C) any loop D) none
9. What will be the output of the inner loop?
10. for(int i=1; i<=2; i++)
11. for(int j=1; j<=3; j++)
12. [Link](j);

A) 123123 B) 123 C) 12 D) 112233

13. In nested loops, if the outer loop runs 3 times and inner loop runs 4 times, total
iterations =
A) 4 B) 3 C) 12 D) 7
14. Which loop prints rows in a pattern?
A) Inner loop B) Outer loop C) Both D) None
15. For printing a square pattern of 5 rows × 5 columns, inner loop runs:
A) 5 times B) 25 times C) 1 time D) 10 times
16. Which statement prints output without moving to next line?
A) print B) println C) nextLine D) show
17. Which loop prints columns?
A) inner loop B) outer loop C) both D) main loop
18. Nested loops can be used to print:
A) tables B) patterns C) matrices D) all of these

SECTION C – PROGRAMMING (30 Marks)

(Each program 6 marks. Use nested loops where required.)


16. Write a Java program using nested loops to print the following pattern:
*****
*****
*****

17. Write a Java program using nested loops to print numbers 1 to 5 in each row:
12345
12345
12345

18. Write a Java program using nested loops to print the following pattern:
*
**
***
****

19. Write a Java program using nested loops to print multiplication table from 1 to 5:

(5 rows, each showing multiples of that row number)


20. Write a Java program using nested loops to print this pattern:
1
22
333
4444

JAVA QUESTION PAPER – MEDIUM


LEVEL (Nested Loops) – 50 Marks
SECTION A – THEORY (10 Marks)

(Each question 2 marks.)

1. Explain the working of a nested loop with a proper example showing outer and inner
loop flow.
2. Why is the inner loop dependent on the outer loop? Give one real-life example.
3. How can nested loops be used to print patterns of increasing numbers? Explain.
4. What happens when the inner loop has fewer iterations than the outer loop? Give an
example.
5. Define loop control variable. How many loop control variables are used in nested
loops?

SECTION B – MCQs (10 Marks)

(Each question 1 mark.)

6. Output of the nested loop:


7. for(int i=1; i<=3; i++)
8. for(int j=1; j<=2; j++)
9. [Link](i);

A) 112233 B) 121212 C) 123123 D) 111222

10. In a nested loop, the outer loop usually controls:


A) columns B) rows C) printing D) none
11. How many times will the inner loop run?
12. for(int i=1; i<=4; i++)
13. for(int j=1; j<=3; j++)

A) 3 B) 4 C) 12 D) 7

14. To print a right-angled triangle pattern, which loop controls the number of stars on
each row?
A) outer B) inner C) both D) none
15. Output of:
16. for(int i=1; i<=2; i++){
17. for(int j=1; j<=3; j++)
18. [Link](j+" ");
19. [Link]();
20. }

A) 1 2 3
123
B) 1 2
12
C) 1 1 1
222
D) 3 2 1
321

21. Nested loops are commonly used for:


A) arrays B) matrices C) patterns D) all of these
22. Which loop ends last in nested loops?
A) outer B) inner C) none D) both together
23. Output of nested loop:
24. for(int i=1; i<=3; i++)
25. for(int j=1; j<=i; j++)
26. [Link]("*");

A) *** B) * \n ** \n ***
C) * ** *** D) *****

27. Nested loops help to print patterns in:


A) square shape B) triangle shape C) number grids D) all of these
28. If outer loop executes 5 times and inner loop executes i times, total iterations =
A) 5 B) depends on i C) 25 D) 10

SECTION C – PROGRAMS (30 Marks)

(Each program carries 6 marks.)


16. Write a Java program using nested loops to print the following pattern:
1234
123
12
1

17. Write a Java program using nested loops to print this star pattern:
*
***
*****
*******
18. Write a Java program using nested loops to print a square number grid from 1 to 5:
12345
23456
34567
45678
56789

19. Write a Java program using nested loops to print the multiplication table from 1 to 10 in a
grid format.

20. Write a Java program using nested loops to print this pattern:
A
BB
CCC
DDDD

JAVA QUESTION PAPER – HARD LEVEL


(50 MARKS)
Topic: Nested Loops Only

Section A – Theory (10 Marks)

(Attempt all questions. Each question carries 2 marks.)

1. Explain with an example how loop dependency works in nested loops.


2. Why is the inner loop executed more times than the outer loop? Explain with a
suitable example.
3. Define time complexity for nested loops. How does it affect program performance?
4. What is the difference between nested loops and multiple independent loops?
5. Why do patterns require nested loops? Explain the role of row-control and column-
control variables.

Section B – MCQs (10 Marks)

(Each question 1 mark. Choose the correct option.)

6. In nested loops, the inner loop executes:


A) Before outer loop starts
B) After outer loop ends
C) Fully for each outer loop iteration
D) Only once
7. For printing a 10×10 grid, number of total iterations =
A) 10
B) 20
C) 50
D) 100
8. A nested loop inside another nested loop makes it:
A) 2D loop
B) Multi-level nested loop
C) Infinite loop
D) Recursive loop
9. Which is the correct structure?
A) for(){while(){} }
B) while(){for(){} }
C) Both A and B
D) None
10. Which loop is commonly used in pattern programs?
A) for-for
B) do-while
C) switch-case
D) if-else
11. A triangle pattern needs:
A) 1 loop
B) 2 nested loops
C) 3 loops
D) No loops
12. Which variable usually controls columns?
A) i
B) j
C) k
D) p
13. To print a hollow shape, we check:
A) boundary condition
B) recursion
C) array length
D) exception
14. Which nested loop prints reverse patterns?
A) Outer decreasing, inner increasing
B) Outer increasing, inner decreasing
C) Both A and B
D) None
15. The output of nested loops is mostly printed using:
A) [Link]
B) [Link]
C) [Link]
D) Scanner

Section C – Hard Programs (30 Marks)

(Attempt all. Each program 6 marks.)


Use nested loops ONLY for all questions.

16. Write a Java program using nested loops to print a hollow square of size 7×7.

Example:
*******
* *
* *
* *
* *
* *
*******

17. Write a Java program using nested loops to print the following number pyramid:
1
121
12321
1234321
123454321

18. Write a Java program using nested loops to print the Pascal’s Triangle for 6 rows (no
formulas, only nested loops for pattern alignment and spacing).
19. Write a Java program using nested loops to print a diamond pattern made of “*”.
20. Write a Java program using nested loops to print the following advanced matrix
pattern where numbers increase row-wise:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

JAVA QUESTION PAPER – HARD LEVEL


(50 MARKS)
Topic: Nested Loops Only (NEW SET)

SECTION A – THEORY (10 Marks)

(Each question carries 2 marks.)

1. Define a triangular nested loop structure. How does the inner loop depend on the
outer loop?
2. Explain with example how nested loops can generate 2D coordinates (like (1,1),
(1,2)…).
3. Why is a break inside an inner loop not the same as breaking the outer loop?
4. What is the difference between nested loops and nested conditions inside a loop?
5. Explain how nested loops can simulate matrix multiplication (concept only, no
program).

SECTION B – MCQs (10 Marks)

(Each question 1 mark.)

6. Nested loops are most often used for:


A) 1D array
B) 2D patterns
C) Switch-case menus
D) Exceptions
7. If outer loop runs 5 times and inner loop runs 3 times, total iterations =
A) 5
B) 8
C) 15
D) 53
8. For printing a checkerboard pattern, we need:
A) One loop
B) Two nested loops
C) Three loops
D) No loop
9. In nested loops, variables i and j represent typically:
A) rows and columns
B) columns and rows
C) input and output
D) none
10. To print mirrored patterns, inner loop usually runs:
A) backward
B) forward
C) randomly
D) infinite
11. A nested loop inside a nested loop is called:
A) Recursive loop
B) Multi-level nesting
C) Compiled loop
D) Buffered loop
12. Which loop combination is valid?
A) for → for
B) while → for
C) for → while
D) All of the above
13. A nested loop without braces {} can cause:
A) faster output
B) logical errors
C) instant exit
D) no issue
14. To print inverted numeric patterns, outer loop:
A) increases
B) decreases
C) stays constant
D) loops infinitely
15. Inside nested loops, printing without newline uses:
A) print()
B) println()
C) nextInt()
D) close()

SECTION C – HARD PROGRAMS (30 Marks)

(Attempt all. Each carries 6 marks.)


Use nested loops only.

16. Write a Java program using nested loops to print a spiral number border pattern:
(Numbers only on the border, inside blank)

Example (7×7):
1 1 1 1 1 1 1
1 1
1 1
1 1
1 1
1 1
1 1 1 1 1 1 1

17. Write a Java program using nested loops to print the following hourglass pattern:
***********
*********
*******
*****
***
*
***
*****
*******
*********
***********

18. Write a Java program using nested loops to print a diagonal cross pattern (X-shape):
* *
* *
*
* *
* *

19. Write a Java program using nested loops to print the following number wave
pattern:
1
12
123
1234
12345
1234
123
12
1

20. Write a Java program using nested loops to generate the following checkerboard of
digits (1 & 0):
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
JAVA QUESTION PAPER – ULTRA HARD
LEVEL (50 MARKS)
Topic: Nested Loops Only – Syllabus Safe

✅SECTION A – THEORY (10 Marks)

(All questions are fully inside syllabus. Each carries 2 marks.)

1. What is a nested loop? Give one simple example.


2. Why do patterns require nested loops? Explain with a simple reason.
3. Differentiate between outer loop and inner loop.
4. Why do we use a variable for controlling rows and another for columns?
5. Write two real-life situations where nested loops are useful.

SECTION B – MCQs (10 Marks)

(Same as before — all syllabus-safe.)

6. Nested loops are mainly used for:


A) Patterns
B) File handling
C) Packages
D) Exceptions
7. If outer loop runs 5 times and inner runs 4 times, total iterations =
A) 5
B) 4
C) 20
D) 10
8. Nested loops represent:
A) 2D structure
B) single value
C) scanner input
D) variable name
9. To print a pyramid, the inner loop controls:
A) spaces and stars
B) import statement
C) user input
D) semicolon
10. In nested loops, which loop runs first?
A) Inner loop
B) Outer loop
C) Both together
D) None
11. In a 6×6 pattern, total cells =
A) 30
B) 12
C) 36
D) 6
12. i is usually used for:
A) row
B) column
C) class name
D) output
13. Condition for left diagonal is:
A) i == 1
B) j == 1
C) i == j
D) i != j
14. Hollow shapes depend on:
A) boundary condition
B) random choice
C) importing packages
D) function call
15. A nested loop executes inner loop:
A) only once
B) after program ends
C) for each outer loop
D) never

SECTION C – ULTRA HARD PROGRAMS (30 Marks)

(All are within syllabus. Nested Loops only.)


16. Print a Hollow Diamond With Cross Lines
*
* *
* *
* * *
* *
* *
*

17. Print a Number Sandglass Pattern


1234567
12345
123
1
123
12345
1234567

18. Print a Rotated Double Triangle Pattern


* *
** **
*** ***
**** ****
***** *****
**** ****
*** ***
** **
* *
19. Print a Dual Number Pyramid (Two Pyramids Touching Base)
1 1
121 121
12321 12321
1234321 1234321
12345432123454321

20. Print a Complex Mixed Grid Pattern (7×7 Example)


* 1 * 1 * 1 *
1 * 2 * 3 * 4
* 3 * 5 * 7 *
1 * 4 * 7 * 10
* 5 * 8 * 11 *
1 * 6 * 9 * 12
* 7 * 11 * 15 *

✅100 × 2-Marks Questions with Answers


(Simple, clear, school-level, NO out-of-syllabus content.)

A. Computing & Ethics – Introduction (1–10)

1. What is computing ethics?


Computing ethics refers to the responsible use of computers, digital devices, and the internet
by following moral values, rules, and good behavior.

2. Why is ethics important in computing?


It helps prevent misuse of technology, protects people’s privacy, and encourages honesty and
respect online.

3. Define digital etiquette.


Digital etiquette means using polite and respectful behavior while using computers,
messaging, emailing, or social media.

4. Give one example of an ethical computing practice.


Using strong passwords and not sharing others’ personal information without permission.

5. Give one example of an unethical computing practice.


Using someone else’s Wi-Fi without permission.

6. What is cyber safety?


Cyber safety means taking steps to stay safe from online threats like scams, viruses, and
hackers.

7. Why should students learn computing ethics?


To help them use technology safely, responsibly, and respectfully.

8. What is meant by responsible online behavior?


Posting correct information, avoiding harmful content, and respecting others’ privacy.

9. What is digital citizenship?


Digital citizenship refers to behaving wisely, responsibly, and legally in the online world.
10. How does technology misuse affect society?
It can lead to cybercrime, privacy loss, financial fraud, and spreading of false information.

B. Intellectual Property Rights (IPR) (11–25)

11. What are Intellectual Property Rights?


IPR are the legal rights given to creators for their work such as music, software, books, and
videos.

12. Why are IPR important?


They protect creators from unauthorized copying and encourage innovation.

13. Give one example of intellectual property.


A software program created by a developer.

14. What is copyright?


Copyright is a legal right that allows only the owner to copy, distribute, or modify their work.

15. Give an example of copyright violation.


Downloading paid movies for free from illegal websites.

16. What is plagiarism?


Plagiarism means copying someone’s work and pretending it is your own.

17. How can plagiarism be avoided?


By giving proper credit or citations to original authors.

18. What is a software license?


A software license is permission from the software owner allowing you to use the software
legally.

19. What is open-source software?


Software that is freely available and allows users to see and modify its source code.

20. Give one example of open-source software.


Linux operating system.

21. What is proprietary software?


Software that is owned by a company and requires purchasing or permission to use.

22. Give an example of proprietary software.


Microsoft Office.

23. What is fair use?


Fair use allows limited use of copyrighted materials for education or research without
permission.

24. Why should students respect IPR?


To avoid legal issues and support the hard work of creators.

25. What is digital piracy in terms of IPR?


Illegal copying, distribution, or usage of digital content like games, movies, and software.
C. Privacy & Data Protection (26–40)

26. What is digital privacy?


Digital privacy means protecting personal information shared online.

27. Give an example of personal data.


Name, phone number, or home address.

28. Why is online privacy important?


It protects users from identity theft and misuse of personal data.

29. What is data protection?


Measures taken to secure personal information from unauthorized access.

30. Give one method to protect online data.


Using strong passwords and changing them regularly.

31. What is meant by “consent” in data sharing?


Permission given by the user before their information is collected or used.

32. What is encryption?


A method of converting information into unreadable code to prevent unauthorized access.

33. How can students protect their privacy on social media?


By keeping accounts private and not sharing personal details publicly.

34. What is identity theft?


Stealing someone’s personal information to pretend to be them.

35. What is a privacy policy?


A document explaining how a website collects and uses user data.

36. Give one example of a privacy violation.


Posting someone’s photo online without their permission.

37. What is a secure website?


A website that uses HTTPS to protect data transfer.

38. What is data misuse?


Using someone’s personal information in an unauthorized or harmful way.

39. How can emails be protected from misuse?


By not sharing passwords and avoiding suspicious links.

40. Why should passwords never be shared?


Because others may misuse your accounts or personal data.

D. Spam & Safe Communication (41–55)

41. What is spam?


Unwanted or unnecessary emails, messages, or advertisements.
42. Give one example of spam.
Emails offering fake prizes or lotteries.

43. Why is spam dangerous?


It may contain viruses or phishing links.

44. What is phishing?


Tricking users into giving personal information by pretending to be a trusted source.

45. How can spam be avoided?


By using spam filters and not clicking unknown links.

46. What is email etiquette?


The rules for writing polite and professional emails.

47. Give one example of good email etiquette.


Using a clear subject line.

48. What is a phishing email?


A fake email designed to steal passwords or banking details.

49. Why should attachments from unknown emails not be opened?


They may contain harmful software.

50. What is bulk mailing?


Sending large numbers of emails at once, often used for advertisements.

51. What is a report spam feature?


A tool that helps mark unwanted emails as spam.

52. What is online harassment?


Sending threatening or rude messages to others online.

53. How can students behave ethically in online chats?


By using polite language and respecting others.

54. Why should offensive content not be shared?


It can harm others and is unethical.

55. Give one example of a harmful online message.


Messages promoting scams or false information.

E. Software Piracy & Cybercrime (56–75)

56. What is software piracy?


Using, copying, or distributing software illegally.

57. Give an example of software piracy.


Installing cracked versions of paid software.

58. Why is software piracy harmful?


It causes financial loss to creators and may contain malware.
59. What is cybercrime?
Any illegal activity using computers or the internet.

60. Give one example of cybercrime.


Stealing someone’s online banking details.

61. What is unauthorized access?


Entering a computer system without permission.

62. What is password theft?


Stealing someone’s password to misuse their account.

63. What is cyber fraud?


Deceiving people online to gain money or information.

64. Give one effect of cybercrime.


Loss of money or personal data.

65. Why is damaging computer systems unethical?


It causes financial and data loss to victims.

66. What is identity fraud?


Using stolen identity to commit crimes.

67. What is cyberbullying?


Bullying someone through messages, posts, or emails.

68. Why is cyberbullying harmful?


It affects mental health and personal safety.

69. What is a secure password?


A password that includes letters, numbers, and special symbols.

70. Why should cracked games not be installed?


They may contain viruses and violate ethical rules.

71. What is online cheating?


Using unfair methods like copying answers during online tests.

72. Why is online cheating unethical?


It reflects dishonesty and harms learning.

73. Give one method to prevent cybercrime.


Keep software updated and use antivirus tools.

74. What is computer misuse?


Using a computer to harm others or break rules.

75. Give an example of computer misuse.


Deleting someone else’s files without permission.
F. Hacking & Malicious Code (76–90)

76. What is hacking?


Illegally accessing someone’s computer or network.

77. Why is hacking dangerous?


It can steal data or damage systems.

78. What is a hacker?


A person who breaks into computer systems without permission.

79. What is a virus?


A harmful program that spreads from one computer to another.

80. Give one example of a virus effect.


Deleting or corrupting files.

81. What is malware?


Software designed to damage or steal information from computers.

82. Why is malware harmful?


It can slow down computers and steal data.

83. What is a worm?


A self-replicating malicious program that spreads across networks.

84. What is a Trojan horse?


A malware that looks useful but harms the computer.

85. What is antivirus software?


Software used to detect and remove viruses.

86. How can malware enter a computer?


Through infected email attachments or unsafe downloads.

87. What is a firewall?


A security system that protects computers from unauthorized access.

88. Why should software updates be installed?


To fix security problems and protect against new threats.

89. What is malicious intent?


A plan to harm someone’s computer, data, or privacy.

90. Give an example of malicious intent.


Creating a virus to damage computers.

G. Good Ethical Practices (91–100)

91. Why should we follow ethical practices online?


To stay safe, respectful, and responsible.
92. Give one example of good digital behavior.
Using polite language in chats.

93. What is respecting privacy?


Not viewing or sharing others’ information without permission.

94. Why should strong passwords be used?


To prevent hacking and unauthorized access.

95. What is acceptable computer use?


Using computers only for allowed and positive activities.

96. Give one example of unacceptable use.


Viewing inappropriate or harmful websites.

97. What is responsible file sharing?


Sharing files legally and only with proper permission.

98. Why should cyberbullying be reported?


To protect victims and stop harmful behavior.

99. What is safe browsing?


Visiting only trusted and secure websites.

100. What is digital honesty?


Being truthful online and not misusing technology.

✅100 MCQs — Computing & Ethics (No


Answers, Options on Same Line)
1. Intellectual property refers to: A. Physical things B. Creative works C. Food items D.
Vehicles
2. Copyright protects: A. Software B. Hardware C. Internet D. Electricity
3. Copying software without permission is called: A. Piracy B. Backup C. Sharing D.
Installing
4. Which is an example of personal data? A. IP address B. Shoe size C. Room color D.
Table height
5. Privacy means: A. Hiding devices B. Protecting personal information C. Sharing
passwords D. Selling data
6. Spam refers to: A. Useful mails B. Unwanted mails C. Slow internet D. Virus scan
7. Hacking means: A. Unauthorized access B. Authorized access C. Slow work D.
Restarting
8. A strong password should be: A. Simple B. Short C. Easy to guess D. Complex
9. Malware stands for: A. Machine ware B. Malicious software C. Manual software D.
Mobile software
10. Email spam is: A. Paid ads B. Unsolicited bulk messages C. Important mail D.
Personal mail
11. Software piracy causes: A. Revenue loss B. Faster internet C. Cleaner PC D. Free
updates
12. Ethical computing means: A. Misusing data B. Using computers responsibly C.
Breaking rules D. Cheating
13. Phishing aims to steal: A. Money B. Personal information C. Clothes D. Vehicles
14. Virus spreads through: A. Pen drives B. Books C. Clothes D. Water
15. A copyright symbol shows: A. Free content B. Protected content C. Broken link D.
Spam alert
16. Data protection means: A. Sharing data B. Securing data C. Deleting computer C D.
Formatting
17. A hacker gains access: A. With permission B. Without permission C. Through store
purchase D. At school
18. Trojan is a type of: A. Hardware B. Malware C. Printer D. Keyboard
19. Privacy settings help to: A. Make data public B. Control who sees information C.
Slow internet D. Remove apps
20. Cybercrime is: A. Online crime B. Road accident C. Bank deposit D. Shopping
21. Reporting cyber issues should be done to: A. Teacher/Parents B. Strangers C.
Random people D. Hackers
22. Ethical behaviour online includes: A. Flaming B. Respecting others C. Cyberbullying
D. Stealing data
23. Plagiarism means: A. Original writing B. Copying someone’s work C. Buying books
D. Deleting files
24. Open-source software is: A. Paid B. Free to modify C. Locked D. Not allowed
25. Malware harms: A. Computer B. Pen C. Shoes D. Clothes
26. A secure website starts with: A. http B. https C. ftp D. mailto
27. Cookies store: A. User preferences B. Shoes size C. Book list D. Weather
28. Good password practice: A. Share it B. Change regularly C. Write on desk D. Use
name
29. Cyber safety includes: A. Hiding data B. Safe online behaviour C. Sharing private
info D. Posting everything
30. Firewalls protect from: A. Dust B. Unauthorized access C. Music C D. Charging
31. Encryption means: A. Making data unreadable B. Deleting data C. Printing data D.
Hacking
32. Social engineering attacks: A. Human trust B. Hardware C. Keyboard D. Water
33. Spam filters: A. Remove viruses B. Block unwanted emails C. Format disk D. Install
apps
34. Intellectual property includes: A. Books B. Ideas C. Software D. All
35. Illegal file sharing is: A. Ethical B. Unethical C. Mandatory D. Rewarding
36. Data theft is: A. Stealing data B. Backing data C. Storing photos D. Downloading
apps
37. Cyberbullying means: A. Online harassment B. Teaching online C. Shopping D.
Gaming
38. Digital footprint is: A. Online trail B. Foot size C. Shoe print D. Wallpaper
39. Phishing email asks for: A. Personal info B. Books C. Games D. Water
40. Antivirus detects: A. Movies B. Malware C. Chairs D. Monitors
41. A worm is: A. Hardware B. Self-replicating malware C. Game C D. Tool
42. Backup helps in: A. Data loss B. Data theft C. Memory C D. Network
43. Spam protection involves: A. Opening all mails B. Not clicking unknown links C.
Buying spam D. Deleting system files
44. Ethical users: A. Spread viruses B. Follow rules C. Hack C D. Steal
45. Hacking for fun is: A. Ethical B. Unethical C. Legal D. Required
46. Personal data includes: A. Phone number B. Shoe color C. Pen name D. Bag label
47. Data leaks expose: A. Private information B. Water C. Books D. Cars
48. A digital signature ensures: A. Identity verification B. Computer speed C. Network
speed D. RAM
49. Copyright violation is: A. Fair use B. Illegal copying C. Charging phone D. Printing
50. Good digital etiquette includes: A. Politeness online B. Cyberbullying C. Spamming
D. Trolling
51. Passwords should include: A. Name B. Mixed characters C. Birth year D. Simple
letters
52. Unethical computing includes: A. Stealing data B. Respecting rules C. Privacy
protection D. Reporting issues
53. Intellectual property deals with: A. Creativity B. Electric bill C. Land records D.
Train ticket
54. Cybercrime includes: A. Online fraud B. Brushing teeth C. Cooking D. Riding
55. A bot is: A. Robot program B. USB device C. File D. Monitor
56. Updating OS helps: A. Increase risk B. Improve security C. Delete data D. Slow PC
57. Ransomware demands: A. Money B. Food C. Shoes D. Books
58. Strong passwords avoid: A. Personal info B. Symbols C. Numbers D. Length
59. Sharing photos publicly may harm: A. Privacy B. Network C. RAM D. Printer
60. Ethical users always: A. Use licensed software B. Hack systems C. Spread rumors D.
Spam
61. Data protection laws protect: A. Personal information B. Sports C. Food D. Music
62. Cyber safety rule: A. Meet strangers B. Don’t share personal info C. Trust unknown
links D. Accept all requests
63. Cookies mostly track: A. Browsing habits B. Shoes size C. School bag D. Pen color
64. A spammer sends: A. Unwanted messages B. Homework C. Reports D. Photos
65. Fair use allows: A. Limited use B. Unlimited copying C. Piracy D. Hacking
66. Firewall blocks: A. Unauthorized traffic B. Friends C. Teachers D. Books
67. Copyright gives: A. Ownership B. Unlimited copying C. Free usage D. Open source
68. Keylogger records: A. Keystrokes B. Songs C. Movies D. Photos
69. HTTPS uses: A. Encryption B. Virus C. Dust C D. Power
70. Routers help: A. Connect networks B. Harm PC C. Copy files D. Delete apps
71. Spyware collects: A. Personal info B. Water C. Books D. Games
72. Ethical behaviour online: A. Respect B. Abuse C. Threats D. Stealing
73. Malware types include: A. Virus B. Worm C. Trojan D. All
74. Online theft is: A. Cybercrime B. Fair use C. Safety D. Ethics
75. Posting rude comments is: A. Trolling B. Respectful C. Etiquette D. Kindness
76. A phishing website looks: A. Fake but similar B. Different C. Offline D. Broken
77. Reporting cyberbullying is: A. Correct action B. Wrong C. Illegal D. Unethical
78. Backups protect against: A. Data loss B. Shoes loss C. Water loss D. Book loss
79. A secure account uses: A. 2-step verification B. Weak password C. No lock D.
Sharing login
80. Public WiFi is: A. Risky B. Very safe C. Offline D. Useless
81. Cyber ethics is about: A. Safe behaviour B. Breaking rules C. Hacking D. Spamming
82. Identity theft steals: A. User details B. Shoes C. Games D. Plants
83. Antivirus should be: A. Updated B. Deleted C. Off D. Removed
84. Social media privacy settings: A. Control visibility B. Increase price C. Slow speed D.
Print data
85. Illegal downloading is: A. Piracy B. Safety C. Ethics D. Hardware
86. Copyright violation is: A. Unethical B. Encouraged C. Safe D. Good
87. Password hint should: A. Not be obvious B. Reveal password C. Show name D. Be
same
88. Malware spreads via: A. Infected files B. Air C. Light D. Sound
89. Ethical users do not: A. Plagiarize B. Respect rules C. Use legal apps D. Maintain
privacy
90. Data protection prevents: A. Misuse of data B. Studying C. Eating D. Writing
91. Virus can: A. Damage files B. Clean PC C. Increase RAM D. Charge phone
92. Accepting unknown requests is: A. Unsafe B. Safe C. Ethical D. Required
93. Digital citizenship includes: A. Good online behaviour B. Bullying C. Abuse D.
Piracy
94. Encryption protects: A. Data B. Water C. Plants D. Table
95. Hacking passwords is: A. Illegal B. Legal C. Fun D. Right
96. A botnet is: A. Group of infected computers B. Printer C. Keyboard D. Mouse
97. Public computers require: A. Logout B. Save password C. Share details D. Stay
logged
98. Data theft harms: A. Privacy B. Trees C. Books D. Bags
99. Privacy helps: A. Protect personal info B. Leak data C. Spam D. Hack
100. Ethical computing means: A. Right use B. Wrong use C. Illegal copying D.
Hacking

✅100 Fill in the Blanks — Computing &


Ethics
1. Intellectual property refers to __________ works created by the mind.
2. Copyright provides legal __________ to the creator.
3. Copying software without permission is called __________.
4. Privacy means protecting a person’s __________ information.
5. Unwanted bulk emails are called __________.
6. Unauthorized access to a computer system is called __________.
7. Malware stands for __________ software.
8. A virus can __________ itself from one file to another.
9. Strong passwords should contain __________ characters.
10. A person who steals information online commits __________.
11. A firewall protects against __________ access.
12. Phishing attempts to steal a user’s __________.
13. Spyware secretly collects a user’s __________.
14. A Trojan appears to be useful but is actually __________.
15. Ransomware demands __________ to release data.
16. Good digital etiquette includes being __________ online.
17. Plagiarism means copying someone’s work without giving __________.
18. Open-source software can be freely __________.
19. HTTPS indicates a __________ connection.
20. Cookies store user __________.
21. A worm spreads through a network __________ user help.
22. Data protection laws aim to protect __________ information.
23. Cyberbullying is a form of online __________.
24. Backups help recover data after __________.
25. Encryption converts data into an __________ form.
26. A strong password should not contain __________ details.
27. Spam filters help block __________ emails.
28. Ethical computing means following __________ rules.
29. Hacking is accessing data without __________.
30. A digital footprint is the trace of a person’s __________ activity.
31. Malware can __________ files on a computer.
32. A keylogger records all __________ pressed.
33. Antivirus software helps __________ malware.
34. Data leaks expose a person’s __________ details.
35. Identity theft involves stealing someone’s __________.
36. Online threats can be reduced using __________ verification.
37. Safe browsing means avoiding __________ websites.
38. Students should not share their __________ online.
39. Copyright symbol is denoted by the letter __________.
40. Illegal file sharing is considered __________ behavior.
41. Digital citizenship means using technology __________.
42. Cyber ethics promote good online __________.
43. A hacker often exploits a system’s __________.
44. Personal data includes name, address, and __________.
45. A secure account must use a __________ password.
46. A firewall monitors network __________.
47. Cybercrime is a crime committed using __________.
48. Posting rude comments online is known as __________.
49. Spyware often installs __________ the user’s knowledge.
50. A secure website has a __________ symbol in the address bar.
51. Passwords should be kept __________.
52. Ethical users avoid __________ content.
53. Downloading pirated movies is __________.
54. Malware may slow down the __________.
55. Data protection prevents __________ use of information.
56. Users must log out from __________ computers.
57. Strong passwords should include __________ characters.
58. Spam is often used for __________ advertising.
59. A phishing email may ask for bank __________.
60. Cyber safety helps prevent online __________.
61. A virus needs a __________ to attach to.
62. A worm spreads through __________ on its own.
63. Ransomware locks the __________.
64. Ethical users do not __________ others online.
65. A cookie is a small __________ stored on a computer.
66. Intellectual property includes software, books, and __________.
67. Data theft harms the user’s __________.
68. Malware creators often aim to __________ systems.
69. Encryption helps maintain data __________.
70. A bot is a program that runs __________.
71. Posting someone’s private photo is a violation of __________.
72. Cyber laws help punish online __________.
73. Unethical behaviour online includes __________.
74. A Trojan is a type of __________.
75. Software piracy is __________.
76. Data backup should be done __________.
77. Cyber ethics teach students how to behave __________.
78. Online fraud is a type of cyber __________.
79. A secure password must be __________ characters long.
80. Users should not open unknown email __________.
81. Digital footprints can __________ information about a user.
82. Spyware may monitor browsing __________.
83. Users should install apps only from __________ sources.
84. Digital content should be used with __________ permission.
85. Cybercriminals may steal __________ details.
86. Antiviruses must be regularly __________.
87. Ethical computing avoids causing __________ to others.
88. Posting false rumors online is called __________.
89. A hacker may install __________ on a system.
90. Cookies help websites remember user __________.
91. Online threats include viruses, worms, and __________.
92. Reporting cyberbullying helps protect __________.
93. Personal devices must be kept __________.
94. Cybersecurity includes tools that __________ systems.
95. Data privacy means not sharing __________ information.
96. Malware often hides in unknown email __________.
97. Ethical users do not access blocked __________.
98. Fake websites often try to __________ users.
99. Students should follow proper online __________.
100. Respecting others online is part of good __________.

QUESTION PAPER – Computing & Ethics


(50 Marks)
Time: 1½ Hours
Class: 9 (ICSE)
Topic: Computing and Ethics

Section A – Very Short Answer Questions (1 × 10 = 10 Marks)

(Answer in 1–2 lines)

1. What is meant by Intellectual Property?


2. Define cybercrime.
3. What is spam?
4. What is the purpose of a password?
5. What is malicious code?
6. What does privacy mean in computing?
7. What is software piracy?
8. Define phishing.
9. What is meant by malware?
10. What is data protection?

Section B – Short Answer Questions (2 × 10 = 20 Marks)

(Answer in 3–4 lines)

11. Explain two examples of ethical behaviour on the internet.


12. What are cookies? How are they used in websites?
13. State any two disadvantages of software piracy.
14. Explain the importance of data privacy for students.
15. What is a Trojan horse? Why is it dangerous?
16. What is hacking? Give one example.
17. Explain strong password practices.
18. What is cyberbullying? Mention two ways to prevent it.
19. How does malware spread through email?
20. Explain “digital footprint” with one example.

Section C – Long Answer Questions (5 × 4 = 20 Marks)

(Answer in 6–8 lines)


21. Explain the term Intellectual Property Rights. Describe any three types of digital
materials protected under IPR.
22. What steps can a student take to protect personal data while using the internet?
Explain any four methods.
23. What are the different types of malicious software? Explain any three with examples.
24. Describe the importance of ethical practices in computing. How do they help create a
safer online environment?
25. Explain the term cybercrime. Discuss any three common cybercrimes and how they
affect users.

QUESTION PAPER – Computing & Ethics


(50 Marks)
Class: 9 (ICSE)
Time: 1½ Hours

Section A – Very Short Answer Questions

(1 × 10 = 10 Marks)
(Answer in 1–2 lines)

1. What is meant by digital etiquette?


2. Define the term cyber safety.
3. What is a secure website?
4. What does the term data breach mean?
5. What is identity theft?
6. What is the full form of HTTPS?
7. What is a firewall?
8. What is the meaning of user consent in data sharing?
9. What do you understand by the term online fraud?
10. What is a security patch?

Section B – Short Answer Questions

(2 × 10 = 20 Marks)
(Answer in 3–4 lines)

11. What is the purpose of antivirus software?


12. Explain how fake messages or hoaxes can harm users.
13. What is the importance of reporting cyber incidents to adults or authorities?
14. Mention two ways in which students can maintain online etiquette in group chats.
15. Explain password confidentiality and why it is important.
16. How do online scams trick users into giving information?
17. What is meant by safe downloading practices?
18. Describe any two methods of protecting data on mobile phones.
19. What is two-factor authentication? Give an example.
20. Why is it important to verify the source before clicking a link?
Section C – Long Answer Questions

(5 × 4 = 20 Marks)
(Answer in 6–8 lines)

21. Explain the concept of ethical responsibilities of a computer user. Give four examples
of ethical behaviour online.
22. Discuss the importance of protecting personal information on social media. Mention
four safety measures to be followed.
23. Describe cyberbullying in detail. What are four possible effects it may have on
victims?
24. Explain the different ways in which computers may get infected with harmful
software. Describe four common infection methods.
25. What is digital privacy? Explain four reasons why maintaining digital privacy is
essential for students.
📘 COMPLEX QUESTION PAPER (50
Marks)
40% Theory (20 Marks) + 60% Programming (30 Marks)

Syllabus: OOP, Datatypes, Operators, If-Else, Switch, Loop, Computing & Ethics

SECTION A — THEORY (20 Marks)


(Answer all questions)

1. Answer any TWO of the following (2 × 3 = 6 marks)

a) Explain Encapsulation with a real-life example.


b) What are relational operators? Write any four with meaning.
c) What is data protection on the internet? Explain any two methods.

2. Answer any TWO of the following (2 × 4 = 8 marks)

a) Describe the difference between instance variable vs local variable with code examples.
b) Explain malicious code. Discuss virus, worm, and trojan with differences.
c) What is the significance of switch-case fall-through? Give one example.

3. Answer any ONE of the following (1 × 6 = 6 marks)

a) Explain polymorphism. How does Java achieve compile-time and runtime


polymorphism?
b) Explain software piracy and intellectual property rights.
c) Explain nested loops and describe how they increase time complexity.

SECTION B — PROGRAMMING &


OUTPUT (30 Marks)
(60% of total paper)

4. Predict the output (Answer ANY THREE) (3 × 2 = 6 marks)

(a)
int a = 8, b = 3;
[Link](a % b * (a - b));

(b)
int x = 2;
if(x++ == 2)
[Link](x + 1);
else
[Link](x - 1);

(c)
for(int i=1; i<=3; i++)
{
for(int j=1; j<=i; j++)
[Link](j+" ");
[Link]();
}

(d)
char c = 'A';
switch(c + 1){
case 'A': [Link]("Alpha"); break;
case 'B': [Link]("Beta"); break;
default: [Link]("None");
}

5. Loop Output (Answer ANY TWO) (2 × 3 = 6 marks)

(a)
int s = 1;
for(int i=1; i<=4; i++){
s *= i;
}
[Link](s);

(b)
int n = 5;
while(n > 0){
[Link](n + " ");
n -= 2;
}

(c)
for(int i=10; i>=1; i--){
if(i % 3 == 0)
[Link](i + " ");
}

6. Write programs (Answer ANY TWO) (2 × 4 = 8 marks)

a) Write a Java program to input three numbers and display them in ascending order without
using arrays.
b) Write a program that takes a number and prints whether it is
Prime / Composite / Neither using loops.
c) Write a program using switch that takes an operator (+, –, *, /) and performs the operation
on two numbers.

7. Higher Complexity Programs (Answer ANY TWO) (2 × 5 = 10 marks)

a) Write a Java program to check whether a number is a Strong Number


(sum of factorial of digits = number).

b) Write a Java program using nested loops to print the following pattern:
1
1 2
1 2 3
1 2 3 4

c) Write a Java program that inputs a string and counts


vowels, consonants, digits, spaces, and special characters.

📘 QUESTION PAPER – SET 2 (50 Marks)


Topics: OOP Concepts, Datatypes, Operators, If–Else, Switch, Loops, Computing & Ethics

Format: 40% Theory (20 Marks) + 60% Programming (30 Marks)

SECTION A — THEORY (20 Marks)


1. Answer ANY TWO (2 × 3 = 6 marks)

a) What is Abstraction? Give a real-life example.


b) Differentiate between primitive and reference datatypes.
c) Define hacking. Mention two preventive measures.

2. Answer ANY TWO (2 × 4 = 8 marks)

a) Explain Unary, Binary, and Ternary operators with examples.


b) What is a constructor? Give two features.
c) What is cyberbullying? Mention four ways to stay safe.

3. Answer ANY ONE (1 × 6 = 6 marks)

a) Explain method overloading with code examples.


b) What is data privacy vs data security? Explain with examples.
c) What are good digital etiquette practices? Explain any six.

SECTION B — PROGRAMMING &


OUTPUT (30 Marks)
4. Predict the Output (ANY THREE) (3 × 2 = 6 marks)
(a)
int a = 12, b = 4;
[Link](a / b + a % b);

(b)
int x = 5;
if(--x >= 4)
[Link](x * 2);
else
[Link](x + 3);

(c)
for(int i=1; i<=3; i++){
[Link](i + (i+1) + " ");
}

(d)
char ch = 'C';
switch(ch){
case 'A': [Link]("Apple");
break;
case 'B': [Link]("Ball");
break;
case 'C': [Link]("Cat");
break;
default : [Link]("None");
}

5. Output of Loops (ANY TWO) (2 × 3 = 6 marks)


(a)
int p = 1;
for(int i=2; i<=5; i++){
p += i;
}
[Link](p);

(b)
int i = 1;
while(i <= 10){
[Link](i + " ");
i += 3;
}

(c)
for(int i=15; i>=1; i--){
if(i % 4 == 0)
[Link](i + " ");
}

6. Write programs (ANY TWO) (2 × 4 = 8 marks)

a) Write a program to input a year and check whether it is a Leap Year using if-else.

b) Write a program to input two numbers and find the HCF (GCD) using a loop.

c) Write a switch-case program to display


“Excellent”, “Good”, “Average”, “Poor” based on grade A/B/C/D.

7. Higher Complexity Programs (ANY TWO) (2 × 5 = 10 marks)

a) Write a Java program to input a number and display the


sum of its even digits and sum of its odd digits separately.

b) Write a program using nested loops to print the pattern:


*
* *
* * *
* * * *
* * * * *

c) Write a program to input a string and check whether it is a Palindrome


(without using built-in reverse methods).

✅QUESTION PAPER – SET 3 (HIGH


COMPLEXITY) – 50 Marks
40% Theory (20 Marks) + 60% Programs/Output (30 Marks)

Topics: OOP • Datatypes • Operators • If-Else • Switch • Loops • Computing & Ethics

SECTION A — THEORY (20 Marks)


1. Answer ANY TWO (2 × 3 = 6 marks)

a) Explain the difference between Static Binding and Dynamic Binding.


b) What is a wrapper class? Why is it needed in Java?
c) Define Digital Forgery and mention two ways to prevent it.

2. Answer ANY TWO (2 × 4 = 8 marks)

a) Explain typecasting in Java. Differentiate between implicit and explicit typecasting.


b) What is short-circuit evaluation in logical operators? Give an example.
c) Explain social engineering attacks with any two detailed examples.

3. Answer ANY ONE (1 × 6 = 6 marks)

a) Explain method overriding, its rules, and why it supports runtime polymorphism.
b) What is intellectual property infringement? Explain any four types.
c) Explain in detail how nested loops increase time complexity (O(n²), O(n³)) with
examples.

SECTION B — PROGRAMMING &


OUTPUT (30 Marks)
4. Predict the Output (ANY THREE) (3 × 2 = 6 marks)
(a)
int a = 10, b = 3;
[Link]((a / b) + (a % b) * b);
(b)
int x = 4;
if(x-- > 3 && ++x == 4)
[Link]("OK");
else
[Link]("NO");

(c)
for(int i=1; i<=3; i++){
for(int j=1; j<=2; j++){
[Link](i+j+" ");
}
}

(d)
char c = 'A';
switch(c + 2){
case 'A': [Link]("One"); break;
case 'B': [Link]("Two"); break;
case 'C': [Link]("Three"); break;
default : [Link]("None");
}

5. Output of Loops (ANY TWO) (2 × 3 = 6 marks)


(a)
int s = 0;
for(int i=1; i<=5; i++){
s += i * i;
}
[Link](s);

(b)
int n = 20;
while(n > 0){
if(n % 5 == 0)
[Link](n + " ");
n -= 3;
}

(c)
for(int i=1; i<=4; i++){
for(int j=1; j<=i; j++){
[Link]("*");
}
[Link](" ");
}

6. Programs (ANY TWO) (2 × 4 = 8 marks)

a) Write a program to input a 3-digit number and check whether it is an Armstrong number.

b) Write a program to input a number and print the sum of prime digits and sum of
composite digits separately.

c) Write a switch-case program that takes a month number (1–12) and prints:

 Number of days
 Season (Summer/Monsoon/Winter)
7. Higher Complexity Programs (ANY TWO) (2 × 5 = 10 marks)

a) Write a Java program to print the following pattern using nested loops:
1
2 3
4 5 6
7 8 9 10

b) Write a program to input a string and print:

 Number of uppercase letters


 Number of lowercase letters
 Number of digits
 Number of special characters
(Without using built-in Character methods)

c) Write a program to input N and print the Fibonacci series up to N terms and also print the
sum of all even Fibonacci numbers.

✅QUESTION PAPER – SET 4 (VERY


HARD) – 50 Marks
Advanced Difficulty for Class 9 ICSE (Stays Within Syllabus)

40% Theory (20 Marks) + 60% Programs/Output (30 Marks)

SECTION A — THEORY (20 Marks)


1. Answer ANY TWO (2 × 3 = 6 marks)

a) Explain access specifiers (public, private, protected) with examples.


b) What is operator precedence? Why does Java require precedence rules?
c) Define malware propagation and give any two methods by which malware spreads.

2. Answer ANY TWO (2 × 4 = 8 marks)

a) Explain immutable objects in Java. Why is String immutable?


b) What is logical NOT, and how does it support boolean algebra? Provide an example.
c) Explain pharming and spoofing with real-life examples.

3. Answer ANY ONE (1 × 6 = 6 marks)

a) Explain how polymorphism improves code flexibility and maintainability.


b) What is identity theft? Describe four advanced safety measures to prevent it.
c) Explain how nested loops contribute to pattern generation, searching, and matrix-like
problems.
SECTION B — PROGRAMMING &
OUTPUT (30 Marks)
4. Predict the Output (ANY THREE) (3 × 2 = 6 marks)
(a)
int a = 7, b = 2, c = 5;
[Link](a / b + c % b * a);

(b)
int x = 1;
if(++x == 2 || x++ == 3)
[Link](x);
else
[Link](x + 2);

(c)
for(int i=1; i<=2; i++){
for(int j=2; j>=1; j--){
[Link](i + j + " ");
}
}

(d)
char ch = 'X';
switch(ch - 1){
case 'W': [Link]("West"); break;
case 'X': [Link]("X-ray"); break;
default : [Link]("None");
}

5. Output of Loops (ANY TWO) (2 × 3 = 6 marks)


(a)
int s = 1;
for(int i=2; i<=6; i++){
s = s + (i * (i - 1));
}
[Link](s);

(b)
int k = 30;
while(k >= 5){
if(k % 7 == 1)
[Link](k + " ");
k -= 3;
}

(c)
for(int i=1; i<=4; i++){
for(int j=4; j>=i; j--){
[Link]("#");
}
[Link](" ");
}
6. Programs (ANY TWO) (2 × 4 = 8 marks)

a) Write a Java program to input a number and check if it is a Harshad Number.


b) Write a program to input two numbers and find the LCM using loops.
c) Write a switch-case program to input a day number (1–7) and display:

 Day name
 Whether it is a weekday or weekend

7. Higher Complexity Programs (ANY TWO) (2 × 5 = 10 marks)


(a)

Write a Java program using nested loops to print the pattern:


1
2 4
3 6 9
4 8 12 16

(b)

Write a program to input a string and:

 Count words
 Count characters (excluding spaces)
 Display the reverse of each word separately

Example:
Input: "Java Code"
Output: "avaJ edoC"

(c)

Write a Java program to input a number and check if it is a


Special Number (sum of factorial of digits + sum of digits × 2 = number).
(Example: 19 → 1! + 9! + (1+9)×2)

✅QUESTION PAPER – SET 5 (ULTRA


HARD) – 50 Marks
40% Theory (20 Marks) + 60% Advanced Programming/Output (30 Marks)

Topics: OOP • Datatypes • Operators • If-Else • Switch • Loop • Computing & Ethics

SECTION A — THEORY (20 Marks)


1. Answer ANY TWO (2 × 3 = 6 marks)

a) Explain constructor overloading with an example involving parameter variations.


b) What is variable shadowing in Java?
c) Define cyberstalking. Mention any two advanced preventive measures.

2. Answer ANY TWO (2 × 4 = 8 marks)

a) Explain short-circuit AND & OR with truth table and Java examples.
b) What is multi-factor authentication (MFA)? Why is it more secure than passwords?
c) Explain digital signature, its purpose, and where it is used.

3. Answer ANY ONE (1 × 6 = 6 marks)

a) Explain how method overriding + dynamic dispatch work internally in Java.


b) Discuss ethical responsibilities of students while using AI tools, giving 6 strong points.
c) Explain the role of nested loops in generating matrices, pyramids, and computational
grids with examples.

SECTION B — ADVANCED
PROGRAMMING & OUTPUT (30 Marks)
4. Predict the Output (ANY THREE) (3 × 2 = 6 marks)
(a)
int a = 9, b = 4, c = 2;
[Link](a % b + b * c - a / c);

(b)
int x = 3;
if(++x >= 4 && x-- == 4)
[Link](x + 1);
else
[Link](x - 1);

(c)
for(int i=1; i<=3; i++){
for(int j=1; j<=3; j++){
[Link]((i*j) + " ");
}
}

(d)
char ch = 'D';
switch(ch - 2){
case 'A': [Link]("Apple");
break;
case 'B': [Link]("Banana");
break;
default: [Link]("None");
}
5. Loop Tracing (ANY TWO) (2 × 3 = 6 marks)
(a)
int s = 0;
for(int i=1; i<=6; i++){
if(i % 2 == 0)
s += i * i;
}
[Link](s);

(b)
int k = 50;
while(k >= 10){
if(k % 9 == 2)
[Link](k + " ");
k -= 4;
}

(c)
for(int i=1; i<=5; i++){
for(int j=1; j<=i; j++){
if((i+j) % 2 == 0)
[Link]("@");
else
[Link]("#");
}
[Link](" ");
}

6. Programs (ANY TWO) (2 × 4 = 8 marks)

a) Write a Java program to input a number and check if it is a


Disarium Number
(sum of digits powered to their position = number).

b) Write a program to input a number and find its binary equivalent (without using built-in
methods).

c) Write a switch-case program that inputs a character and checks whether it is


Vowel / Consonant / Digit / Special Character.

7. Higher Complexity Programs (ANY TWO) (2 × 5 = 10 marks)


(a)

Write a Java program using nested loops to print the pattern:


1
1 3
1 3 5
1 3 5 7
1 3 5 7 9

(b)

Write a Java program to input a string and:


 Extract all vowels into one new string
 Extract all consonants into another string
 Display both in sorted order (no built-in sort)

(c)

Write a program to input a number N and:

 Print all perfect numbers ≤ N


 Also print the count of perfect numbers found
(Use nested loops for divisor checking)

Common questions

Powered by AI

Primitive data types in Java represent single values and are not objects. These include int, char, double, byte, etc. They are predefined by Java and have a fixed size, leading to more efficient performance. In contrast, non-primitive data types (also known as reference types) include classes, interfaces, and arrays. They can store references to objects and offer more flexibility, although with a potential increase in memory usage and processing time .

Encapsulation in Java is the wrapping of data and methods that operate on the data within a single unit or class. This is implemented by using private access modifiers for data fields and providing public getter and setter methods to access and update them. Encapsulation enhances security by restricting direct access to sensitive data, ensuring that it can only be manipulated through controlled interfaces, thus upholding data integrity .

In Java, '=' is the assignment operator used for assigning values to variables. For example, 'int a = 5;' assigns the value 5 to the variable 'a'. In contrast, '==' is the equality operator used to compare two operands for equality, returning true if they are equal and false otherwise. Therefore, 'a == 5' checks if the value of 'a' is equal to 5 .

Inheritance in Java allows a new class (subclass) to inherit the fields and methods of an existing class (superclass). This enables code reuse, as common functionalities need not be rewritten. Moreover, it promotes maintenance and scalability, as changes in the superclass automatically propagate to subclasses. For instance, if a superclass 'Vehicle' defines methods like 'move()', subclasses like 'Car' and 'Bike' inherit these, allowing developers to focus on adding specific functionalities such as 'openTrunk()' or 'pedal()' without replicating common 'Vehicle' behaviors .

Literal constants in Java are fixed values written directly in the program's code, such as numbers, characters, or strings. They differ from variables in that literals represent constant values that do not change throughout the execution, whereas variables are named memory locations whose values can be modified during program execution .

Boolean operators in Java, such as && (AND) and || (OR), are used in conditional expressions to combine multiple boolean conditions. Java employs short-circuit evaluation for these operators, meaning evaluation stops as soon as the result is determined. For example, in the expression (false && true), the evaluation stops after encountering 'false', as the whole expression cannot be true. This feature improves efficiency and avoids executing unnecessary operations or encountering runtime errors, such as null pointer exceptions .

Operator precedence and associativity are critical in determining the order in which operators are executed in complex Java expressions. Precedence dictates which operators are evaluated first in expressions without parentheses. For instance, '*' has higher precedence than '+', impacting expressions like 'a + b * c'. Associativity determines the order of evaluation when multiple operators of the same precedence appear, such as left-to-right for '-' and right-to-left for assignment operators ('='). Understanding these rules is essential for predicting and controlling expression outcomes accurately .

Polymorphism in Java allows objects to be treated as instances of their parent class rather than their actual class. This is key for dynamic method dispatch, where the method called on an object at runtime can be of any specific subclass. For example, if a superclass 'Animal' has a method 'sound()', subclasses like 'Dog' and 'Cat' can override this to provide specific implementations. A variable of type 'Animal' can hold reference to any subclass object, and the appropriate 'sound()' method is executed at runtime based on the object's actual class .

The 'new' keyword in Java is used to create new instances of a class (objects). It allocates memory for the object and returns a reference to that memory. This is essential for object-oriented programming in Java, as classes serve as blueprints from which objects are constructed. By using 'new', you can instantiate a class and invoke its constructor to initialize the object .

Operator precedence determines the order in which operations are performed in a Java expression. Operators with higher precedence are evaluated before those with lower precedence. For example, in the expression 3 + 4 * 2, the multiplication (*) takes precedence over addition (+), resulting in 3 + (4 * 2) = 3 + 8 = 11. Parentheses can be used to explicitly specify the order, e.g., (3 + 4) * 2 = 7 * 2 = 14 .

You might also like