Checking /* Filename: "Checking.java" * Created by 1,000_naymes for ICT 352 * * Purpose: Asks user for integer input & determines whether or not integer(s) are divisible * by 5 and 6, neither, or one of them. * */ import javax.swing.JOptionPane; public class Checking { public static void main( String[] args ) { /************************************************************** declare and initialize variables **************************************************************/ String openingMessage, bothMessage, neitherMessage, eitherMessage, numberInputMessage, numberString; int number, divided5, divided6; /************************************************************** setting messages and displaying opening message **************************************************************/ openingMessage = "Welcome to 1KN's Dividing program, which will investigate whether your number is \ndivisible by 5, 6, both, or neither."; JOptionPane.showMessageDialog( null, openingMessage ); /************************************************************** input for number **************************************************************/ numberInputMessage = "Please enter your number."; numberString = JOptionPane.showInputDialog( numberInputMessage ); number = Integer.parseInt( numberString ); //converting string to integer bothMessage = number + " is divisible by both 5 and 6."; neitherMessage = number + " is not divisible by 5 or 6."; eitherMessage = number + " is either divisible by 5 or by 6."; /************************************************************** calculations on number **************************************************************/ divided5 = number % 5; // looking for a remainder divided6 = number % 6; // looking for a remainder boolean both = divided5 == 0 && divided6 == 0; boolean neither = divided5 > 0 && divided6 > 0; boolean either = divided5 > 0 || divided6 >0; /************************************************************** divisible decision **************************************************************/ if( both ) JOptionPane.showMessageDialog( null, bothMessage ); else if( neither ) JOptionPane.showMessageDialog( null, neitherMessage ); Page 1
Checking else if( either ) JOptionPane.showMessageDialog( null, eitherMessage ); System.exit(0); } //end main }
Page 2