Create a program that lists all divisors of an integer x G F
Create a program that lists all divisors of an integer x G Following is list ofthe divisors Please enter a numberbelow 10
Solution
Program:
import javax.swing.*;
public class divisions
{
public static void main(String[] args)
{
JFrame frame = new JFrame(\"Divisions\");
String input = JOptionPane.showInputDialog(frame, \"Please enter a number below:\");
divisors(Integer.parseInt(input));
}
public static int divisors(int num)
{
String output=\"\";
for(int i=1;i <= num;i++)
{
if(num%i == 0)
output = output+i+\"\ \";
}
textArea = new JTextArea(output);
textArea.setEditable(false);
}
}
