Skip to main content

Posts

Showing posts with the label Class 9

Write a program to accept the starting and ending range. Display the sum of even and odd numbers .

Write a program to accept the starting and ending range. Display the sum of even and odd numbers . import java.util.Scanner; public class Range {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);                                   System.out.println("Enter the starting and ending range:");         int m = sc.nextInt();         int n = sc.nextInt();         if(m<n){             int so=0,se=0;             for(int i=m;i<=n;i++)             {                 if(i%2==0)                 {                     se=se+i;        ...

Write a program to accept 50 numbers. Count and display the numbers which are positive and negative.

Write a program to accept 50 numbers. Count and display the numbers which are positive and negative. import java.util.Scanner; class posneg {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter 50 numbers:");         int nc=0,pc=0;         for(int i=1;i<=50;i++)         {             System.out.println("Enter number:");             int n=sc.nextInt();             if(n>=0)             {                 pc=pc+1;                 System.out.println(n+" is positive number");             }             else{          ...

ICSE Class 9 Up to Conditional Statements 100 MCQs with answers

**Theory-Based Questions (1-50)** **1. Which of the following is a low-level language?**   A) Java   B) Python   C) Assembly Language   D) C++   **Answer: C** **2. What is the function of an assembler?**   A) Converts high-level code to machine code   B) Converts assembly code to machine code   C) Converts bytecode to machine code   D) Converts source code to object code   **Answer: B** **3. Which principle of OOP allows a function to be used for multiple purposes?**   A) Encapsulation   B) Inheritance   C) Polymorphism   D) Data Abstraction   **Answer: C** **4. Which Java package is imported by default?**   A) java.util   B) java.io   C) java.lang   D) java.awt   **Answer: C** **5. What is the extension of a Java source code file?**   A) .class   B) .java   C)...

ICSE Class 9 Loop based Multiple Choice Questions With Explanation

92 MCQ Set Of Questions **1. What is the output of the following code?** ```java int a = 5, b = 2; int result = a++ * --b; System.out.println(result + " " + a + " " + b); ``` a) 10 6 1 b) 5 6 1 c) **5 6 1** d) 10 5 1 **2. What will be the value of `sum` after execution?** ```java int sum = 0; for(int i = 1; i <= 5; i+=2) {     sum += i; } ``` a) 6 b) 9 c) **15** d) 10 **3. Predict the output:** ```java int x = 10; if(x++ > 10 && ++x < 12) {     System.out.println(x); } else {     System.out.println(x+1); } ``` a) 10 b) 11 c) **12** d) 13 **4. What does this code print?** ```java System.out.println(13 / 5 + " " + 13 % 5); ``` a) 2.6 3 b) 2 3 c) **2 3** d) 3 2 **5. What is the output?** ```java int a = 1; int b = a++ + ++a * a++; System.out.println(b); ``` a) 10 b) **11** c) 12 d) 13 *Explanation: The expression is evaluated as 1 + (3 * 3). a++ is 1 (then a=2), ++a makes a=3, the third a++ is 3 (then a=4). So 1 + 9 = 10.* **6. Predict the ou...

CBSE Class 9 AI Chapter 8 Computer System MCQs

**Components of Computer System: Multiple Choice Questions** **1. What are the three main types of components in a computer?** a) Hardware, Software, Peripheral b) Input, Processing, Output c) CPU, RAM, Hard Drive d) Monitor, Keyboard, Mouse **Answer: b) Input, Processing, Output** **2. According to the document, what is the role of input devices analogous to in a human?** a) The brain b) The hands and legs c) The five senses d) The memory **Answer: c) The five senses** **3. Which of the following is NOT a hardware component?** a) Microsoft Excel b) Monitor c) Motherboard d) Keyboard **Answer: a) Microsoft Excel** **4. The Central Processing Unit (CPU) is responsible for all EXCEPT:** a) Controlling the sequence of operations b) Storing data permanently c) Providing instructions to other parts d) Controlling the memory **Answer: b) Storing data permanently** **5. Which component of the CPU is responsible for performing arithmetic operations like addition and subtraction?** a) Control U...

ICSE Class 9 Notes: Inputs in Java

 Inputs in Java Errors: are basically programming problems which we face while solving a problem.  There are different types of errors: 1) Syntax Error or Compile-Time Error: are the errors which immediately detected by the javac compiler during compilation. The common mistakes that causes syntax or compile time errors are: 1) Missing semicolon 2) Misspelling of identifiers and keywords 3) Use of undeclared variables. 4) Incompatible types in assignments or initializations 5) Use of = in place of == operator 6) Missing braces {} in classes and methods. and many more 2) Run Time Error: the error that appears during the run or execution time of a program other than the syntax error is called runtime error. The common mistakes that causes runtime errors are: 1) Dividing a number by zero. 2) Passing a parameter that is not in a valid range or value for method. 3) While entering data during the program execution, entering an integer into a string data type will result in an error. ...