9/27/10



Divisors of a Number (Java Program)

9/27/2010

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 + " ");
}

}

}



Your thoughts about this post? Leave a commment now.

Posted by

AndyFGo : A place for Pinoy Music News. Lyrics. Music Videos. Pinoy Movie/Foreign Trailers. OPM.

 

© 2013 andyfgo. All rights reserved. Designed by Templateism. Powered by Blogger
Protected by Copyscape DMCA Takedown Notice Violation Search

Back To Top