Page 221 - Computer science 868 Class 12
P. 221

6.  Convert the following code to Ternary Operator.
                       if(a>=b && a<c)
                          System.out.println(a+b);
                       else
                          System.out.println(a*b);
                    7.  Find the output of the following code.
                       if(1 + 1 + 1 + 1 + 1 == 5)
                       {
                         System.out.print("TRUE");
                       }
                       else
                       {
                         System.out.print("FALSE");
                       }
                    8.  Find the output of the following code.
                       class Solution{
                          public static void main()
                          {
                             int i;
                            for(i = 1; i < 6; i++)
                          {
                             if(i > 3)
                                 continue;
                                }
                                 System.out.println(i);
                            }
                          }
                    9.  What does the following code do?

                       int i, s;
                         s = 0;
                       for(i=1; i<=10; i++)
                       {
                          if(10%i==0)
                          {
                             s=s+i;
                          }
                       }
                       System.out.println(s);
                   10.  Find the error in the following code.
                       Int i=10;
                       while(i>=1);
                       {
                          System.out.println(i*10);
                          i=i-1;
                       }
                    11.  A class Numbers contains the following data members and member functions to check for the triangular numbers. [A triangular
                       number is formed by the addition of a consecutive sequence of integers starting from 1.]
                        For example,
                         1 + 2 = 3
                         1 + 2 + 3 =6
                         1 + 2 + 3 + 4 =10
                         1 + 2 + 3 + 4 + 5 = 15
                        Therefore 3, 6, 10, 15 are triangular numbers.
                        Class name                      :    Numbers




                                                                                                                       219
                                                                                                 Statements and Scope  219
   216   217   218   219   220   221   222   223   224   225   226