![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find all divisors of a natural number in java
Following is the Java program which prints all the divisors of a given number.
Program
import java.util.Scanner; public class DivisorsOfNaturalNumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter required number :"); int num = sc.nextInt(); for(int i = 1; i<num; i++) { if(num % i == 0) { System.out.println(" "+i); } } } }
Output
Enter required number : 200 1 2 4 5 8 10 20 25 40 50 100
Advertisements