Page 96 - CA_Blue( J )_Class10
P. 96

catch(Exception ex)
                    {
                    }
                 10.  The following two methods are written to calculate the area and diameter of a circle. But, the code contains four errors.
                    Identify them and correct the code.
                       public void Area(double r)
                       {
                           duble a;
                           a = 3.14 * r * r;
                           System.out.println("Area is: "+ a)
                       }
                       public void diameter()
                       {
                           double dia = radius + 2;
                            System.out.printlm("Diameter is: "+ dia);
                       }
                Ans.  The following are the errors in the first method:
                    •  The spelling of double is incorrect while declaring the variable a inside the Area( ) method.
                    •  Semicolon is missing from the fifth line
                    The following are the errors in the second method:
                    •  The + symbol is used instead of * symbol to calculate the diameter of the circle.
                    •  The spelling of println( ) method is wrong.
                       public void Area(double r)
                      {
                          double area;
                          area = 3.14 * r * r;
                           System.out.println("Area is: "+ area);
                      }
                      public void diameter()
                      {
                          double dia = radius * 2;
                           System.out.println("Diameter is: "+ dia);
                      }

              D.  Assertion and Reasoning based questions.
                    The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
                    appropriate option given below:
                    a.  Both A and R are true, and R is the correct explanation of A.
                    b.  Both A and R are true, but R is not the correct explanation of A.
                    c.  A is true, but R is false.
                    d.  A is false, but R is true.
                  1.  Assertion (A): Scanner class can only read data of type String.
                     Reason (R): The Scanner class has methods like nextInt(), nextDouble(), and nextBoolean() to read different types of data.
                  2.  Assertion (A): Arithmetic Exception is thrown when a division by zero occurs.
                     Reason (R): Arithmetic Exception is a runtime exception that indicates an exceptional arithmetic condition.
                  3.  Assertion (A): IOException is a logical error.
                     Reason (R): IOException occurs during input and output operations and must be caught or declared to be thrown in the method
                    signature.
                Ans.  1. d    2. a    3. d
                                                                                                21 st
              E.  Case-based Questions.                                                      Century   #Experiential Learning
                                                                                               Skills
                  1.  Ramesh write a program to input a number in double type. So, he writes double d= sc.nextInt(); Now , will he able to take execute
                    the line and when he prints the variable d using the following statement "System.out.println(d);"what will be the output if 4 is
                    taken as input?



                9494  Touchpad Computer Applications-X
   91   92   93   94   95   96   97   98   99   100   101