write a program that will read in a positive integers and pr

write a program that will read in a positive integers and print all of the factors of the number. note: Factors are numbers that divide evenly into the number. to calculate modulus, we use the % symbol

Solution

FactorsOfNumber.java

import java.util.Scanner;

public class FactorsOfNumber {

   public static void main(String[] args) {
  
       //Declaring variables
       int number,count=0;
      
       //Scanner class object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //Getting the number entered by the user
       System.out.print(\"Enter a number :\");
       number=sc.nextInt();
      
       /* Checking whether the user entered number
       * is greater than count variable or not
       */
       while(count<number)
       {
           //Incrementing the count value
           ++count;
          
           /* Checking whether the user entered number
           * is divisible by count value or not
           */
           if(number%count==0)
           {
               //Displaying the factors
               System.out.println(count+\" is a factor of \"+number);
           }
       }

   }

}

_______________________________

output:

Enter a number :51
1 is a factor of 51
3 is a factor of 51
17 is a factor of 51
51 is a factor of 51

_______________________________

Output2:

Enter a number :69
1 is a factor of 69
3 is a factor of 69
23 is a factor of 69
69 is a factor of 69

__________Thank You

write a program that will read in a positive integers and print all of the factors of the number. note: Factors are numbers that divide evenly into the number.
write a program that will read in a positive integers and print all of the factors of the number. note: Factors are numbers that divide evenly into the number.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site