Friday, 16 August 2024

Robotics & Artificial Intelligence Class 9 ICSE

Robotics and AI - PR Webmatrix

Please scroll down. You will get a specimen question paper.

Sample Paper 1

Section A

Question 1

Choose the correct answers to the questions from the given option.

i. Three laws of Robotics are created by

    (a) Stephen Hawking

    (b) Victor Scheinman

    (c) Elon Asima

    (d) Isaac Asimov

ii. The characteristics of a robot do not include(s):

    (a) Robots cannot move

    (b) It can be designed to perform disastrous tasks

    (c) It can be programmed to perform a variety of ethical tasks.

    (d) Robots are always controlled by humans

iii. Actuators can be considered as:

    (a) Human Head

    (b) Human muscles

    (c) Human hands

    (d) None of these

iv. Which of the following is/are robotic component(s)?

    (a) Sensor

    (b) Controller

    (c) Actuator

    (d) All of these

v. How many Degrees of Freedom (DoF) does a robot arm with a single revolute joint has?

    (a) One

    (b) Two

    (c) Three

    (d) Four

vi. Which of the following describes a robot's movements in two dimensions?

    (a) Extending a robotic arm

    (b) Rotation around a fixed axis

    (c) Straight line movement

    (d) Moving in a circle

vii. The structure of neural networks was inspired by:

    (a) Human brain structure

    (b) Computer programming

    (c) Logical Reasoning

    (d) Statistical analysis and data modelling

viii. Which of the following can be performed in AI in an email system?

    (a) Filter incoming mails

    (b) Prioritise emails

    (c) Grammar Correction

    (d) All of these

ix. Information can be defined as:

    (a) Raw Facts

    (b) Abrupt sentences

    (c) Processed data

    (d) Collection of dates only

x. Which platform(s) use(s) recommendation systems?

    (a) YouTube

    (b) Netflix

    (c) Amazon

    (d) All of these

xi. Which of the following is not a characteristic of deterministic computing?

    (a) Non adaptable

    (b) Randomness

    (c) Accurate results

    (d) Discrete Data

xii. To adapt the changes, AI model requires ...........................

    (a) History Data

    (b) New Updated Data

    (c) Diverse Data

    (d) Discrete Data

xiii. Which of these is the first stage of the AI project framework?

    (a) Data Collection

    (b) Problem definition and scope

    (c) Evaluation

    (d) Modelling

xiv. Which of the following is not an expert system?

    (a) DENDRAL

    (b) MYCIN

    (c) XCON

    (d) Image classification system

xv. Which of these is the primary purpose of data in AI?

    (a) To train AI models

    (b) To generate revenue

    (c) To develop algorithms

    (d) None of these

xvi. The suitable computing technique for a problem of classifying temperature as hot or cold is:

    (a) Binary Logic

    (b) AI Computing

    (c) Deterministic computing

    (d) Probabilistic computing 

xvii. Which of the following is true for lists in Python?

    (a) Lists are mutable

    (b) Lists are immutable

    (c) Tuple and Lists both are immutable

    (d) None of these 

xviii. What will be the output of the following statement?

            print(a) if a>b else print (b)

    (a) It will give an error

    (b) It will print the larger number

    (c) It will print the smaller number

    (d) None of these

xix. The function of 'else' in 'if-else' statement is:

    (a) To execute the block of statement when the condition is True

    (b) To execute the block of statement when the condition is False

    (c) To specify an alternative condition

    (d) None of these

xx. In Python, which keyword is used to terminate a loop immediately?

    (a) exit

    (b) return

    (c) break

    (d) continue


Question 2

i. What do you understand by Collaborative robots? Explain with the help of an example.

Ans: Collaborative robots are also called cobots and they are designed to work alongside humans and assist them in tasks that require both human skills and machine precision. These are smaller and lighter than traditional industrial robots and they are equipped with sensors to detect and avoid obstacles.

For example, the first collaborative robot, the Universal Robot, was developed in 2008 by Universal Robots. It was a six-jointed articulated robot arm that revolutionized the market for industrial robots.

ii. What are the main components of a robot?

Ans: There are six important components of a robot which are as follows:

    a) Sensors
    b) Actuators
    c) Controllers
    d) Power Systems
    e) Communication Systems
    f) Manipulators

iii. Explain end-effectors with the help of an example.

Ans: Robot end effector is a device attached to the wrist of a manipulator for the purpose of holding materials, parts, tools to perform a specific task.

Examples:

    a) Grippers
    b) Tools
    c) End of arm tooling
    d) Welding Equipment

iv. Explain the difference between Angular motion and linear motion of a robotic arm.

Ans:  

Angular Motion

Linear Motion

Angular motion refers to the rotating movement of an object or a component of a system around a fixed point or axis.

Linear motion refers to the movement of a robot in a straight line along a specific path.

Following are the key properties of an object showing angular motion

 

The object rotates in a plane perpendicular to the axis of rotation.

Angular velocity describes the rate at which an object or a component of a system rotates.

Following are the key properties of an object that exhibits linear motion:

 

Straight Path

Constant Velocity or Acceleration








v. Write some examples of activities that involve a robot arm to move in two dimensions.

Ans: Two dimensional motions are required for tasks such as drawing figures on a plane surface, navigating a maze, and executing pick and place operations on a surface. Two dimensional motion permits the arm's movement in a plane, which increases the range of reachable orientations as well as positions, making it suitable for tasks involving object interaction in a a two-dimensional environment.

vi. Which decade was the peak of AI development and why?

Ans: The duration from 2000 to 2010 was the peak of AI tool development. The concept of deep learning, which includes the specialized artificial neural networks, gained high popularity during this time. The availability of large amount of data, programming support, and data storage support through cloud helped researchers execute complex deep learning algorithms in easy and efficient manner.

vii. What do you understand by Accountability in terms of AI Ethics?

Ans: In terms of AI Ethics, Accountability tells who is accountable or responsible for AI Systems' activities and consequences or results, including their creators, operators, and organizations. Accountability also includes continuous monitoring and optimisation of AI systems.

viii. How does data visualization help in understanding data?

Ans: Data visualisation techniques allow the graphical representation of data in the form of charts, graphs or diagrams. Data visualisation can reveal patterns, trends or relationships within the data, making it simpler to recognize important features and understand the data. Bar graphs, scatter plots, histograms, heat maps, and line graphs are examples of typical visualisation tools.

ix. What do you understand by Data privacy and ethics in AI? Explain.

Ans: As the use of Artificial Intelligence grows, data privacy and ethical considerations become very important. Responsible AI development requires protecting sensitive data, obtaining informed consent, and adhering to ethical practices throughout the data collection and usage process.

x. Explain Narrow AI with the help of an example.

Ans: Narrow AI refers to artificial intelligence systems that are designed to perform specific tasks such as voice recognition or image analysis. It's the most common type of AI that we encounter in our daily lives. Examples include the voice assistants on our phones like Siri and Google Assistant, recommendation algorithms used by Netflix and Amazon, and the AI that powers autonomous vehicles.

Section B

Question 3

What are the various characteristics of a robot? Explain each of them by considering an example of a medical surgery robot.

Ans: Various characteristics of robots are as follows:

  • Autonomy: Robots can operate independently or with minimal human intervention. Surgical robots can independently make decisions regarding the whole surgical procedure, including preoperative workflows.
  • Adaptability: Surgical Robots will cater to increasing surgical procedures as they become more versatile and adaptable. Patients can benefit from reduced trauma, quicker recoveries, and smaller incisions.
  • Durability: Robotic surgery allows doctors to perform many types of complex procedures with more precision, flexibility and control than is possible with traditional procedures. Robotic surgery is often performed through tiny incisions.
  • Accuracy: Surgical Robots are capable of performing tasks with a high degree of accuracy and precision. Robot-assisted surgery currently has an overall success rate of 94% to 100%.
  • Learning: Surgical Robots can learn from their experiences and improve their performance over time. Autonomous surgical robots have the potential to transform surgery and increase access to quality health care.
  • Safety: Surgical Robots can speed up healing and lessen pain while giving surgeons more or better control. They have been designed with safety features to prevent harm to humans or any other objects.

Question 4

How do links and joints help in linear motion? What are the benefits of more Degrees of Freedom in robots?

Ans: With the help of links and joints, linear motion is produced in following ways:

  • Prismatic Joints: A prismatic joint allows only translation along a fixed line. Usually, in a robot, complex joints are constructed by combining simple rotational and prismatic elements.
  • Link length and Orientation: The size and direction of linear motion depends on the links' length and orientation. The intended linear trajectory can be obtained by properly designing and positioning the linkages.
  • Coordinated Joint Movement: Coordinated joint control is required to produce linear motion at prismatic joints. The speed and direction of linear motion are determined by the joint movement's velocity and direction.
  • Actuation and Control: Actuators supply the required force or pressure to drive the prismatic joints and permit linear motion.
Benefits of more Degree of Freedom are as follows:
  • More Degree of Freedom allows a greater range of motion and reach. It permits the robot to traverse complex paths.
  • Increased adaptability: Robots with greater DoF can adapt to a wider variety of working conditions and objects. They can dynamically alter their configuration and movement in response to environmental changes.
  • Human-like movements: Robots with greater DoF may intimate human-like movements and postures, allowing for more natural interactions with humans. This is especially useful in applications like human-robot collaboration.

Question 5

Explain the applications of AI in banking and healthcare.

Ans: 

Applications of AI in banking are as follows:

  • Fraud detection: By observing regular transaction pattern of a customer, a suspicious  transaction can be identified to find out any fraudulent activity.
  • Customer service: AI enabled chatbots can be used to provide 24 X 7 service to customers. These chatbots can answer queries of customers like interest rate on loan or any particular scheme, procedure to open any bank account etc.
  • Robotic advisers: Robotic advisers are used to provide right investment advice to customers. Customers can take advice from these robots based on their investment capacity, financial goals, risk tolerance capacity etc.
  • Risk assessment: Risk assessment is an essential component in banking while approving a loan. AI algorithms help in analysing risk factor of a customer based on his and his family member's credit history.
  • Cyber security: AI can enhance cyber security measures by analysing network traffic, identifying potential threats, and detecting unusual transaction activities that could indicate a security breach. It helps banks in real time threat detection and prevention.
Applications of AI in healthcare are as follows: 

  • Diagnosis of diseases: AI algorithms can help in diagnosing diseases through patient history, symptoms and medical records. For example, AI enabled tools can generate a warning message regarding a disease for a person based on his symptom and lifestyle.
  • Drug Discovery: New drug discovery requires a lot of historical data analysis. Many different combinations are also being generated. AI can help in analysing huge amount of biomedical data in identifying potential drug combinations. It also predicts the effectiveness and side effects of a drug.
  • Personalised medicine: AI can help in prescribing personalised medical treatments to individual patients. It can be done by analysing their genetic information, medical history and lifestyle data etc.
  • Virtual assistants: AI assisted virtual assistants can help in handling patient's queries. They also offer full time support to monitor the physical and mental health of patients. 
  • Robotic surgery: AI enabled robots are used for performing complex surgery. Robotic surgery helps enhance surgical accuracy and improves the results of surgery.
  • Healthcare administration: AI can be used to streamline different administrative tasks, like management of medical records, appointment scheduling, billing etc. which will help in better hospital administration.

Question 6

What do you mean by deterministic computing? What are the various characteristics of deterministic computing? What are the various limitations of deterministic computing?

Ans: Deterministic computing refers to a computing paradigm in which the output and behaviour of a system are completely determined by its input and a set of predefined rules or algorithms. In deterministic computing, the execution of computations does not allow randomness or flexibility.

The main characteristics of deterministic computing are as follows:

  • Consistency: In Deterministic computing, executing of a program or system always produces the same output for a given input, regardless of how many times, it is executed. This consistency guarantees repeatability and predictability of outcomes.
  • Non adaptability: Deterministic computing is dependent on predefined algorithms or sets of rules that control the system's behaviour. These algorithms define the sequence of operations to be executed based on the input without variation.
  • Absence of randomness: Deterministic computing does not contain random elements. The computations are based on logical operations, arithmetic calculations and if-then statements.
The main limitations of deterministic computing are as follows: 

  • Rigidness: Deterministic computing is rigid since it is based on pre-programmed instructions and predefined algorithms. It is incapable of adjusting to new or changing data and learning from it.
  • Lack of reasoning capability: Deterministic computing struggles with situations that needs reasoning, judgement and pattern identification.
  • Handling incomplete data: In order to deliver trustworthy results, Deterministic computing often requires the submission of complete and accurate data. It may struggle with incomplete, noisy or unclear data.
  • Lack of context understanding: Deterministic computing runs on established principles and lacks complete knowledge of the context or relevance of the data it analyses.
  • Creativity and innovation limitations: In Deterministic computing, it is difficult to produce novel solutions or identify new patterns.


Sample Paper 2

Section A














END OF SPECIMEN PAPER

Very Important for ICSE 2025

PR Webmatrix

Dear ICSE Students,

Welcome to my blog dedicated to helping you navigate the fascinating world of Computer Science! Whether you're just starting to explore the subject or preparing for your exams, this space is designed to be your go-to resource for guidance, tips, and insights.

I understand that Computer Science can sometimes seem daunting with its intricate concepts and ever-evolving technologies. That's why we're here to simplify things for you. 

Feel free to explore my articles, tutorials, and study resources. Don't hesitate to reach out with your questions or suggestions – I'm here to support you every step of the way.

Happy learning!

Keep visiting the page on a regular basis for new contents


Question 1: What does the below image represents?

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

A

Answer: A multidimensional array with 5 Rows and 5 Columns

Description: Multidimensional Array is considered as an Array of Arrays. Such arrays are considered useful when we want to store data as a tabular form like a table with Rows and Columns.

Similar Question

What does the following image represents?

O

O

O

O

O

O

O

O

O

O

O

O

O

O

O

Answer: A multidimensional array with 3 Rows and 5 Columns

Draw a multidimensional array having 3 rows and 6 columns.

Answer: 

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

Question 2: Name the feature due to which Java Compiled codes can run on Linux although the code was developed in MAC.

Answer: Platform Independent

Description: Java is essentially Platform Independent. Change of platform does not affect the original Java program/application.

Similar Question

Name the feature due to which no huge coding is required in Java.

Answer: Light Weight Code.

Description: With Java, no huge coding is required.

Question 3: What is the size of '\n'?

Answer: The size of '\n' is 2 bytes.

Description: '\n' is one of the escape sequence and it is equivalent to one character. Size of character in Java is 2 Bytes and therefore, size of '\n' is 2 bytes.

Similar Question

What is the size of '\t'?

Answer: The size of '\t' is 2 bytes.

Description: '\t' is one of the escape sequence and it is equivalent to one character. Size of character in Java is 2 Bytes and therefore, size of '\t' is 2 bytes.

Question 4: Which arithmetic operator gets the highest precedence while evaluating the following statement?

a1+b1*c1%d1-e1

Answer: *

Description: While evaluating the above statement, the * operator will get the highest precedence because although * and % is given in this expression and they have the same precedence but in terms of their associativity, left to right is followed which means out of * and %, whoever comes first will get the higher precedence.

Similar Question

Which arithmetic operator gets the highest precedence while evaluating the following statement?

7%7*9/3+2

Answer: %

Description: While evaluating the above statement, the % operator will get the highest precedence because although %,* and / is given in this expression and they have the same precedence but in terms of their associativity, left to right is followed which means out of %,* and /, whoever comes first will get the higher precedence.

Question 5: Name some valid Java Keywords.

Answer: Some valid Java Keywords are as follows:

  1. for
  2. switch
  3. if
  4. boolean
  5. while
  6. return
Question 6: What will be the output after executing the below statement?

System.out.println(Math.ceil(6.1)+Math.Floor(-1-2));

Answer: 4.0

Description: The ceil() function returns the smallest whole number greater than on equal to the parameter value. (Rounded Up). Here, as 6.1 is mentioned within ceil, so it is giving 7.

The floor() function returns the largest whole number less than or equal to parameter value. (Rounded Down). Here, as -1-2 was mentioned within floor, so, it is giving -3

So, after calculating 7-3, it is giving 4.

As the Math Functions available in Math Class always returns value of type double due to which, answer shall be in decimal value and hence, answer shall be 4.0.

Similar Question

What will be the output after executing the below statement?

System.out.println(Math.abs(Math.max(-9.6,-2.8));

Answer: 2.8

Description: As per the statement, first the max() function of Math class will execute which will give the output as -2.8. As per statement, now -2.8 is contained with abs() function of Math class which will return the absolute value of the number. Absolute value means positive value.

What will be the output after executing the below statement?

System.out.println(Math.max(16,(Math.max(19,6));

Answer: 19

Description: As per the statement, first the inner max() function of Math class will execute which will give the output as 19 as maximum number among 19 and 6 is 19. Now, the statement will become something like this

System.out.println(Math.max(16,19);

Now, it is clear that the maximum number between 16 and 19 is 19. Hence, 19 is the output.


Question 7: Name the accessor method of the String Class which returns a new string resulting from replacing all occurrences of oldChar with newChar.

Answer: String replace(char oldChar, char newChar)

Description:

replace() method has two parameters namely:
  • oldChar - Old Character
  • newChar - New Character
Refer to the below program for a clear understanding of the replace() method.

class HelloWorld
{
    public static void main(String[] args) 
    {
        String S="Computer Science";  
        String S1=S.replace('e','a');
        //replaces all occurrences of 'e' to 'a'  
        System.out.println(S1);
    }
}

After executing the above code, output shall be:
Computar Scianca

Similar Question

Give a demonstration of the accessor method of the String Class which returns a new string resulting from replacing all occurrences of oldChar with newChar.
[Hint: Information Technology shoule be displayed as Infermatien Technelegy]

class HelloWorld
{
    public static void main(String[] args) 
    {
        String S="Information Technology";  
        String S1=S.replace('o','e');
        //replaces all occurrences of 'o' to 'e'  
        System.out.println(S1);
    }
}

After executing the above code, output shall be:

Infermatien Technelegy


Question 8: Will it be true to say that switch statement supports floating point constants?

Answer: No

Description: Switch statements does not support floating-point constants or expressions as case labels. This limitation is due to the nature of how switch statements are typically implemented and optimized for efficiency. Many compilers prohibits the use of floating-point constants in switch statements. If used, it results in a compilation error or a warning.

Similar Question

Switch statement checks for equality between the input and case labels (True/False)
True

In Switch case, break is used to exit from the Switch block (True/False)
True

In Switch case, case labels are unique (True/False)
True

Question 9: What will be the output of the following statement?
public class Operator
{
    public static void main(String[]args)
    {
        char ch[]={'A','E','I','O','U'};
        System.out.println(ch[1]*2);
    }
}

Answer: 138

Description: In this code, a character array having 5 elements was declared. In the print statement, it is written as ch[1]*2 which means that the element at the 1st Index needs to be multiplied by 2. The element at 1st index is E because in array, index position begin with 0. Now, the program will first get the ASCII code of E which is 69. 
Now, as per the statement, it is mentioned as ch[1]*2 which means, 69 * 2 resulting to which, 138 will come as output.

Similar Question

What will be the output of the following statement?
public class Operator
{
    public static void main(String[]args)
    {
        int a[]={7,12,5,6,7,9,15,92};
        System.out.println(a[5]*12);
    }
}

Answer: 108

Description: 

Index Position

a[0]

a[1]

a[2]

a[3]

a[4]

a[5]

a[6]

a[7]

a

7

12

5

6

7

9

15

92


Element at index position a[5] is 9. When it will get multiplied by 12, it will give output as follows:

108

Write a java program to print the length of the following array:

char x[]={'A','E','I','O','U'};

Answer:

public class Operator
{
    public static void main(String[]args)
    {
        char x[]={'A','E','I','O','U'};
        System.out.println("Length of the array is "+x.length);
    }
}

After execution, the output will be as follows:

Length of the array is 5

Question 10. How many times, the following loop statements will execute?

a) for(int a = 11;a<=30;a+=2)
Answer:

The above loop when executed will produce the following output:
11
13
15
17
19
21
23
25
27
29

Hence, we can see that the loop will execute for 10 times.

b) for(int a = 11;a<=30;a+=3)
Answer:

The above loop when executed will produce the following output:
11
14
17
20
23
26
29

Hence, we can see that the loop will execute for 7 times.

c) for(int a = 11;a<20;a++)
Answer:

The above loop when executed will produce the following output:
11
12
13
14
15
16
17
18
19

Hence, we can see that the loop will execute for 9 times.

d) for(int a = 11;a<=21;a++)
Answer:

The above loop when executed will produce the following output:
11
12
13
14
15
16
17
18
19
20
21

Hence, we can see that the loop will execute for 11 times.

Question 11. Suppose, a single dimensional array has 5 elements in it. Write an array declaration to initialize the last element of the array to 50.

Answer: int a[4] = 50;

Description: Below is the structure of an array. In the following array, there are 5 elements in it. Array index positions starts from 0 and that's why, it is clearly seen that the first index position is 0 and last index position is 4. In the following array structure,

1st element is containing 20
2nd element is containing 21
3rd element is containing 30
4th element is containing 8
5th element is containing 50

Index

a[0]

a[1]

a[2]

a[3]

a[4]

a

20

21

30

8

50

Elements

1

2

3

4

5


Similar Question

Suppose a single dimensional array has 6 elements in it. Write an array declaration to initialize the 3rd element of the array to 70.

Answer: int b[2] = 70;

Suppose a single dimensional array has 9 elements in it. Write an array declaration to initialize the 2nd last element of the array to "Rohit".

Answer: String name[7] = "Rohit";

Description: Rohit is a word, hence String data type has been taken. name is taken as the name of the array. Total element in array is 9. As array elements starts from 0 and hence, the last index position of the array is 8.

 

1st element

 

 

 

 

 

 

 

Last element

0

1

2

3

4

5

6

7

8

 

 

 

 

 

 

 

Rohit

 

 

Question 12. Write a method prototype for the method display which accepts two integer arguments and returns true/false:

Answer: boolean display(int a, int b)

Description: As asked in question, a method prototype for the method namely display having two integer arguments were passed as parameters(). As integer variable names were not there, so we created our own variable namely a and b. At last, it is mentioned that the method should return the value in true/false and due to which boolean data type has been taken as we all know that boolean data type can store true or false values.

Similar Question

Write the prototype of the function verifies that accepts character chr and integer x and returns true or false.

Answer: boolean verifies(char chr, int x)

Write the function prototype for the function Poschar which takes a string argument and a character argument and returns an integer value.

Answer: int Poschar(String str, char ch)


Question 13. Name the statement that brings the control back to the calling method.

Answer: return

Description:

The “return” keyword can help in transferring control from one method to the method that called it. Since the control jumps from one part of the program to another, the return is also a jump statement like break and continue.

“return” is a reserved keyword means we can’t use it as an identifier.

Similar Question

Name the statement that terminates the current loop or switch statement.

Answer: break

Description: The break statement is one of the jump statements that terminates the current loop or switch statement. The execution then continues from the statement immediately following the current loop or switch statement. The break statement consists of the keyword break followed by a semicolon.

Syntax of break statement:

break;

Name the statement that instructs the computer to skip the rest of the current iteration of the loop.

Answer: continue

Description: The continue statement is one of the jump statements that instructs the computer to skip the rest of the current iteration of the loop. Unlike the break statement which forces termination of the loop, the continue statement forces the next iteration of the loop to take place, skipping any instructions in between. The continue statement consists of the keyword continue followed by a semicolon.

Syntax of continue statement:

continue;

Question 14. Name the data type that can store true or false values.

Answer: boolean

Description:

boolean data type is used to store logical values. It can store only true or false.
Although the boolean data type needs only one bit of storage, the Java compiler reserves 8 bits (1 byte) for it.

Example of boolean Data type:

public class booleandemo
{
    public static void main(String[]args)
    {
        boolean x = true;
        boolean y = false;
        System.out.println(x);
        System.out.println(y);
    }
}

After executing the above code, following will be the output:

true
false


Question 15. Write a program to accept a string, then convert it into uppercase and finally, display the first alphabet of each word.

Answer:

import java.util.*;

class Hello

{

    public static void main(String[]args)

    {

        Scanner sr = new Scanner(System.in);

        System.out.println("Enter a string:");

        String S = sr.nextLine();

        String Su = S.toUpperCase();

        System.out.println(Su.charAt(0));

        for(int i = 0;i<Su.length();i++)

        {

            if(Su.charAt(i)== ' ')

            {

                System.out.println(Su.charAt(i+1));

            }

        }

    }

}


Let us Dry run the program:

1st, Enter a string will be displayed.

sr.nextLine(); will accept the input from user and will store the string in the variable namely S of String data type.

S.toUpperCase(); will convert the string into uppercase letters and the converted uppercase letters will be stored in the variable namely Su of String data type.

System.out.println(Su.charAt(0)); will print the first character of the string.

A loop have been created to ensure that it can read the characters from index number 0 till last index number. (index of an array is always -1 than the length of the array). It is accomplished using the code below:

for(int i = 0;i<Su.length();i++)

The statement i.e.,  if(Su.charAt(i)== ' ') within the for loop block will search for a space.

If it finds space, then the following statement will get executed or else the loop will keep on executing till it reaches the last index position:

System.out.println(Su.charAt(i+1));

The above statement will print the character whose index is next to the index in which space is present.

In this way, the program will print the first alphabet of each word on the screen.


Question 16. Consider the following program

public class hello
{
    void swap(int i, int j)
    {
         i = j;
         j = k;
         int k = 0;
         k = i;
         System.out.println(i);      
    }
}

What will be the output of the above program? If any problem is encountered, rewrite the program for getting desired output.

Answer:

The above program when executed will show error as follows:
Undeclared variable: k

The corrected code should be like this:

public class hello
{
    void swap(int i, int j)
    {
        int k = 0; 
        k = i;
        i = j;
        j = k;
        System.out.println(i);      
    }
}

Description: Here, problem is with the arrangement of statement within the swap method. Simply, we need to change the ordering of the statements written inside the swap method.

Question 17. Write a Java program to print the length of the array.

Answer:

public class arraylength
{
    public static void main(String[]args)
    {
        int arr[]={2,6,8,12,37};
        System.out.println("Length of the array is: "+arr.length);      
    }
}

After executing the above program, following will be the output:

Length of the array is: 5

Question 18. What will be the output after executing the below program?

public class hello
{
    public static void main(String[]args)
    {
        int x = 2,y = 3;
        y*=x++ - ++y + ++x;
        System.out.println("x= "+x);
        System.out.println("y= "+y);
    }
}

Answer:

x= 4
y= 6

Description:

y = y*2-4+4;
y = 3*2-4+4;
y  = 6-4+4;
y = 2+4
y = 6

Present value of x is 4 and after evaluation, value of y became 6.
(Operator precedence is taken care of while evaluating the above expression)

Question 19. XYZ is a student of class X and while executing the code, error have been encountered. Identify the error and rewrite the code.

public class hello
{
    public static void main(String[]args)
    {
        boolean inp = true;
        switch(inp)
        {
         case 1:
                 System.out.println("Congratulations");
         case 2:
                 System.out.println("Better luck next time");
        }
    }
}


Answer:

The above program when executed will produce the following error:

Incompatible types: int cannot be converted to boolean.

The corrected code shall be:

public class hello
{
    public static void main(String[]args)
    {
        int inp = 1;
        switch(inp)
        {
         case 1:
                 System.out.println("Congratulations");
         case 2:
                 System.out.println("Better luck next time");
        }
    }
}

Question 20. Write a Java program to print the value of x = a2+2ab where a varies from 1.0 to 6.0 with increment of 2.0 and b=3.0 is a constant.

Answer:

public class hello
{
    public static void main(String[]args)
    {
        final double b = 3.0;
        for(double a = 1.0;a<=6.0;a+=2)
        {
            System.out.println("Value of x when a is "+a+" : "+Math.pow(a,2)+2*a*b);
        }
                 
    }
}

After executing the above program, the output shall be:

Value of x when a is 1.0 : 1.06.0
Value of x when a is 3.0 : 9.018.0
Value of x when a is 5.0 : 25.030.0


Question 21. Convert the following complex program into a simple program:

class Hello
{
    public static void main(String[]args)
    {
        char character = 'a';
        if(character == 'a')
            {
                System.out.println("Vowel");
            }
        if(character == 'A')
            {
                System.out.println("Vowel");
            }
    }
}

Answer:

The simplest form of the same program is shown below:


class Hello
{
    public static void main(String[]args)
    {
        char character = 'a';
        if(character == 'a' || character == 'A')
            {
                System.out.println("Vowel");
            }
    }
}

Question 22. How many times, the following loop will execute? Write the output of the code.

class Hello
{
    public static void main(String[]args)
    {
        int x = 10;
        while(true)
        {
        System.out.println(x++*2);
        if(x%3==0)
        {
            break;
        }
        }
    }
}

Answer: The above loop will execute for 2 times.

Output shall be as follows:

20

22

Question 23. What will be the output after executing the below program?

class Hello
{
    public static void main(String[]args)
    {
        String a = "Guava", b = "Green";
        System.out.println(a.charAt(0)==b.charAt(0));
        System.out.println(a.compareTo(b));
    }
}

Answer: After executing the above program, the output shall be:

true

3

Description:

String a

String b

 

Guava

Green

 

The charAt() method returns the character at the specified index in a string.

The index of the first character is 0, the second character is 1, and so on.

Character at 0 index is G

Character at 0 index is G

G==G, hence it will give result as true

The compareTo() method compares two strings lexicographically.

The comparison is based on the Unicode value of each character in the strings.

Character at 0 index is G

ASCII code of G is 71

Character at 0 index is G

ASCII code of G is 71

71-71=0

compareTo() method will now go to index 1 and so on until it doesn’t finds any positive integer value to be displayed.

Character at 1 index is u

ASCII code of u is 117

Character at 1 index is r

ASCII code of u is 114

117-114=3


Question 24. What will be the output after executing the below program?

class Hello
{
    public static void main(String[]args)
    {
        char ch = 'B';
        char chr = Character.toLowerCase(ch);
        int n = (int) chr-10;
        System.out.println((char)n+"\t"+chr);
    }
}

Answer: After executing the above program, the output shall be:

 

X             b

Description:

ch namely variable is holding B in it.
With the help of string accessor method i.eCharacter.toLowerCase(ch), B have been converted to b and this lowercase letter b have been stored into chr.
The next line i.e. int n = (int) chr-10 states that the value contained within chr needs to be converted into integer and then, it should be subtracted by 10.
chr is a variable containing b in it. ASCII code of b is 98 and when it is subtracted by 10, it becomes 88. So, now 88 is stored into the new integer variable namely n.
In the print statement, it can be seen that the integer variable n is again getting converted to character. n is holding 88 and character X have the ASCII code 88. So, first X will get printed. Then "\t", the escape sequence character will insert a tab and finally, value stored in chr will get displayed which is b. Hence, output is coming as:

X             b

Question 25. Write a java program to accept a number using string data type. Then, convert the string to a numerical value so that square root of the converted value can be obtained.

Answer:

import java.util.Scanner;
class Hello
{
    public static void main(String[]args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number");
        String s = sc.nextLine();
        double x = Double.parseDouble(s);
        double r = Math.sqrt(x);
        System.out.println(r);
    }
}

Description:

As it is asked, user input have been stored in a String variable namely s. Say for example, 25 have been given by user that is stored in s. Double.parseDouble() is used to parse String to double means that value stored as string can be converted using this method. Value of 25 which was stored as a string in variable namely s have been converted into double value and it is now stored in a variable called x. Now, x is containing 25. Then with the help of Math.sqrt() function, square root of x have been determined and it is stored in a new variable r. Finally, r is displayed.

Question 26. Write a Java Program to show a multiplication table. Ensure that the number of which multiplication table needs to be shown is accepted from the user.

Answer:

import java.util.Scanner;
class hello
{
   public static void main(String[]args)
   {
       Scanner KBD = new Scanner(System.in);
       System.out.println("Enter a number");
       int number = KBD.nextInt();
       for(int i = 1;i<=10;i++)
       {
           System.out.println(number+" X "+i+" = "+number*i);
       }
   }
}

Question 27. Write a Java Program to accept a string from user, convert it into uppercase and then replace the vowels with the next character following it.

Hint:
Input: Computer
Output: CPMPVTFR

Answer:

import java.util.Scanner;
class Vowelreplace
{
    public static void main(String[]args)
    {
        Scanner sr = new Scanner(System.in);
        int i,len;
        String word,newword = "";
        char ch, ch1;
        System.out.println("Enter a Word:");
        word = sr.nextLine();
        word = word.toUpperCase();
        len = word.length();
        for(i = 0;i<len;i++)
        {
            ch = word.charAt(i);
            if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
            {
                char nextchar = (char)(ch+1);
                newword = newword+nextchar;
            }
            else
            {
                newword = newword+ch;
            }
        }
        System.out.println("The converted string is:"+newword);
    }
}

See the complete demonstration of the above program by clicking here.

Question 28. Consider the following program segment and answer the questions given below:

int x[][] = {{2,4,5,6},{5,7,8,1},{34,1,10,9}};

(a) What is the position of 34?

Answer:

In order to find the position of an element, first, let us draw the structure of an array:

 

 

Columns

 

 

0

1

2

3

Rows

0

2

4

5

6

1

5

7

8

1

2

34

1

10

9

 

As per the above diagram, we can see the location of 34. 34 is located at an intersection of 2 and 0. In multidimensional array, index position of row is written first and then, index position of column is written.

Here, row is 2 and column is 0. Hence, location of 34 is x[2][0]

(b) What is the result of x[2][3] + x[1][2]?

Answer:

x[2][3] = 9
x[1][2] = 8

9+8 = 17

(c) What is the result of x[0][2] * x[2][3]?

Answer:

x[0][2] = 5
x[2][3] = 9

5*9 = 45

(d) What is the result of x[0][2] * x[2][3] + x[2][2]?

Answer:

x[0][2] = 5
x[2][3] = 9
x[2][2] = 10

5*9+10 = 55

Question 29. Write a java program to find the number of rows and columns in the following array structure:

 

S

U

N

D

A

Y

M

O

N

D

A

Y

 

Answer:

public class Operator
{
    public static void main(String[]args)
    {
        char x[][]={{'S','U','N','D','A','Y'},{'M','O','N','D','A','Y'}};
        System.out.println("Number of row is "+x.length);
        System.out.println("Number of column is "+x[0].length);
    }
}

Question 30. Write a java program to print the following pattern

    

    2 2 

    3 3 3 

    4 4 4 4 

    5 5 5 5 5


Answer:

class HelloWorld 
{
    public static void main(String[] args) 
    {
        for(int i = 1;i<=5;i++)
        {
            for(int j = 1;j<=i;j++)
            {
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}


Question 31. Write a java program to print the following pattern

1 1 1 1 1 
2 2 2 2 2 
3 3 3 3 3 
4 4 4 4 4 
5 5 5 5 5

Answer:

class HelloWorld 
{
    public static void main(String[] args) 
    {
        for(int i = 1;i<=5;i++)
        {
            for(int j = 1;j<=5;j++)
            {
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

Question 32. Write a java program to print the following pattern

1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5

Answer:

class HelloWorld 
{
    public static void main(String[] args) 
    {
        for(int i = 1;i<=5;i++)
        {
            for(int j = 1;j<=5;j++)
            {
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Question 33. Write a java program to print the following pattern

LL
UUU
EEEE

Answer:

class HelloWorld 
{
    public static void main(String[] args) 
    {
        String Word = "BLUE";
        for(int i = 0;i<Word.length();i++)
        {
            for(int j = 0;j<=i;j++)
            {
                System.out.print(Word.charAt(i));
            }
            System.out.println();
        }
    }
}

Question 34. Define a class series to display the sum of the series given below:

x1+x2+x3..........xn terms

Let x = 1 and n = 10

Answer:

class Series 
{
    public static void main(String[] args) 
    {
        int x = 1;
        double sum = 0;
        for(int n = 1;n<=10;n++)
        {
            sum = sum+Math.pow(x,n);
        }
        System.out.println("Sum of the series is "+sum);
    }
}