Page 183 - CA_Blue( J )_Class10
P. 183

System.out.println("Grade A");
                       else
                       if(m>70)
                       System.out.println("Grade B");
                       else
                       if(m>50)
                       System.out.println("Grade C");
                       else
                       System.out.println("Grade D");
                       }
                          }
                      }
                    33.  Write a menu-driven program to print the following series:
                                 th
                       i.  1,4,9,……n  term
                          2
                              6
                            4
                       ii.  a ,a ,a ,……n  term
                                   th
                   Ans. import java.util.*;
                      class series_switchcase
                      {
                          public static void main () {
                               Scanner sc = new Scanner (System.in);
                               int i, n, a, ch;
                               System.out.print("Enter n : ");
                               n=sc.nextInt();
                               System.out.println("1. Series 1");
                               System.out.println("2. Series 2");
                               System.out.println("Enter your choice :");
                               ch=sc.nextInt();
                               switch(ch)
                               {
                                 case 1: for(i=1;i<=n;i++)
                                {
                                 System.out.print(i*i);
                                }
                                break;
                                case 2:   System.out.print("Enter a : ");
                                a=sc.nextInt();
                                for(i=1;i<=n;i++)
                                {
                                System.out.print(Math.pow(a,(i*2))+ " , " );
                                }
                                     break;
                                 default:  System.out.println("Wrong Choice");
                            }
                      }
                      }
                    34.  Write a program to print the sum of numbers that ends with 3 and the square of numbers that are multiples of 4. The program
                       will continuously input value as long as the user wants.
                   Ans.  import java.util.*;
                      class sum_product
                      {
                            public static void main () {
                            Scanner sc = new Scanner (System.in);
                            int m, s=0, p = 1;
                            boolean cod=true;
                            char a = ' ';
                            while(cod)
                            {



                                                                                                                       181
                                                                                              Iterative constructs in Java  181
   178   179   180   181   182   183   184   185   186   187   188