Page 292 - CA_Blue( J )_Class9
P. 292

VARIABLE DESCRIPTION
                             NAME              DATATYPE                           DESCRIPTION

                        n                int                    Accept a number
                        i                int                    Loop Variable
                        s                int                    Sum of the series
                        j                int                    Loop Variable

                                  Write a program to input 2 numbers m and n (m<n) and print the factors of each number
                   Program 15
                                  between them.
                     1     import java.util.*;                                       //importing “util”package
                     2     class factor                                              //class name

                     3     {
                     4         public static void main()

                     5         {
                     6             Scanner sc= new Scanner(System.in);

                     7             int m,n,i,s,j;                                    //Declaration of variable
                     8             System.out.print("Enter m : ");                     //Accepting range
                     9             m=sc.nextInt();

                   10              System.out.print("Enter n : ");

                   11              n=sc.nextInt();
                   12              System.out.println("The factors of all the numbers between "+ m +" and
                               "+ n +" : ");
                   13              System.out.print("-----------------------------------------------");

                   14              i=m;
                   15              while(i<=n)

                   16              {
                   17                  System.out.print("\nThe factors of "+ i+ " are : ");

                   18                  j=1;
                   19                  while(j<=i)

                   20                  {
                   21                      if(i%j==0)

                   22                      {
                   23                          System.out.print(j+" ");

                   24                      }
                   25                      j++;

                   26                  }
                   27                  i++;



                   290    Touchpad Computer Applications-IX
   287   288   289   290   291   292   293   294   295   296   297