Page 176 - CA_Blue( J )_Class10
P. 176

a++;
                        System.out.print (a+ " : ");
                     }
                Ans.  int a,b;
                     a=2;
                     b=18;
                     while(a<=10)
                     {
                        a++;
                        System.out.print(a+" : " );
                        b=b-2;
                     }
                 10.  Print the output of the program of question 9:
                Ans.  3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 :
                 11.  Identify the errors in the following code and write the correct code:
                    for (int i = 1, i <= 10; i=i++)
                     {
                          System.out.print(i * i + " : ");
                     }
                Ans.  for (int i = 1; i <= 10; i++)
                     {                                                                 //[Explanation: 1  instead of, it will be;
                                                                                                     st
                         System.out.print(i * i + " : ");
                                                                                            //2  instead of i=i++, it will be i++]
                                                                                              nd
                     }
                 12.  Convert from do-while to while loop:
                    int i=1, j=10;
                     do
                     {
                         i++;
                         System.out.println(i+2);
                         j--;
                     }while(i<j);
                Ans.  int i=1, j=10;
                     while(i<j)
                     {
                       i++;
                       System.out.println(i+2);
                       j--;
                     }
                 13.  Convert to for loop and write the output:
                    int i=10;
                    do
                    {
                       System.out.println(Math.pow(i,2));
                       i--;
                    } while(i>=10);
                Ans.  for (int i=10; i>=10; i--)
                    {
                       System.out.println(Math.pow(i,2));
                    }
                     Output: 100.0
                 14.  Convert to for loop:
                    int n=456, r;
                    while(n>0)
                    {



                174174  Touchpad Computer Applications-X
   171   172   173   174   175   176   177   178   179   180   181