Write a program to input a number and find all the factors (including 1 and excluding the number
itself) of that number. in java
Answers
Answered by
1
Answer:
Explanation:
dont know
Answered by
0
Hope it helps ^_^
This is the base program
I have also added all the possible outputs
import java.util.Scanner;
public class FactorTeller{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int i, num;
System.out.print("Enter a number in order to know its factors: ");
num = sc.nextInt();
System.out.println("The factors of the given number are as follows: ");
for (i = 1; i <= num; i++){
if(num % i == 0){
System.out.println(i);
}
}
}
}
Outputs:
Enter a number in order to know its factors: 20
The factors of the given number are as follows:
1
2
4
5
10
20
Similar questions
Math,
1 month ago
Physics,
1 month ago
Computer Science,
1 month ago
Hindi,
4 months ago
Social Sciences,
10 months ago
Math,
10 months ago