import javax.swing.JOptionPane;
public class DivisorsOfANumber{
public static void main(String[] args){
String input;
int number;
int numberDivisors = 0;
int moduloAnswer;
here:
do{
input = JOptionPane.showInputDialog(null, "Enter a positive real number:", "Divisors of A Number", JOptionPane.INFORMATION_MESSAGE);
number = Integer.parseInt(input);
if(number<0){
JOptionPane.showMessageDialog(null, "Invalid number! A positive number should be needed to enter", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}
if(number == 0)
JOptionPane.showMessageDialog(null, "Error! No possible divisor for zero.", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}while(number<=0);
System.out.print("The divisors of " + number + " are : ");
for(int possibleDivisors = 1; possibleDivisors<=number; possibleDivisors++){
if((number % possibleDivisors)==0)
System.out.print(possibleDivisors + " ");
}
}
}
public class DivisorsOfANumber{
public static void main(String[] args){
String input;
int number;
int numberDivisors = 0;
int moduloAnswer;
here:
do{
input = JOptionPane.showInputDialog(null, "Enter a positive real number:", "Divisors of A Number", JOptionPane.INFORMATION_MESSAGE);
number = Integer.parseInt(input);
if(number<0){
JOptionPane.showMessageDialog(null, "Invalid number! A positive number should be needed to enter", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}
if(number == 0)
JOptionPane.showMessageDialog(null, "Error! No possible divisor for zero.", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}while(number<=0);
System.out.print("The divisors of " + number + " are : ");
for(int possibleDivisors = 1; possibleDivisors<=number; possibleDivisors++){
if((number % possibleDivisors)==0)
System.out.print(possibleDivisors + " ");
}
}
}
Your thoughts about this post? Leave a commment now.