Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //program that shows the factors of the given number
- //author: jp hernandez
- //date: 7/23/2015
- //import statements
- import javax.swing.*;
- public class factorial2 { //public class scope
- public static void main(String args[]){ //start of main
- //initialization of variables
- String temp;
- short number;
- short limit;
- temp = JOptionPane.showInputDialog(null,"What are the factors of"); //ask for the number using GUI
- number = Short.parseShort(temp); //then store it in variable number
- limit = number; //we copy the value entered in number to the limit variable for later use
- System.out.print("\nThe factors of " + number + " are: ");
- //next, we will create a for loop for the factor running algorithm
- for(int counter=1; counter<=limit ; counter++ ){//starting the loop up to the limit set
- if(limit%counter==0){ //check if the current counter number is a factor
- System.out.print(counter + " "); //printing if true, otherwise, continue until the limit
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement