Page 208 - CA_Blue( J )_Class9
P. 208

9             n=sc.nextInt();
                    10             System.out.print("The factors of "+n +" are : ");

                    11             i=1;
                    12             while(i<=n)

                    13             {
                    14                 if(n%i==0)
                    15                 {   System.out.print(i+" ");

                    16                 }

                    17                 i++;
                    18             }
                    19         }

                    20      }

                  You will get the following output:













                   Program 10     Input a number and print the factors of the number using do while loop.


                     1     import java.util.*;
                     2     class dowhile_factors

                     3     {
                     4         public static void main()
                     5         {

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

                     7             int i,n;
                     8             System.out.print("Enter a number : ");
                     9             n=sc.nextInt();

                    10             System.out.print("The factors of "+n +" are : ");
                    11             i=1;

                    12             do
                    13             {







                   206    Touchpad Computer Applications-IX
   203   204   205   206   207   208   209   210   211   212   213