Checking

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Checking as PDF for free.

More details

  • Words: 256
  • Pages: 2
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

Related Documents

Checking
November 2019 23
Checking Criteria.docx
April 2020 9
Just Checking
November 2019 22
Firehose Checking
June 2020 7
Desk Checking
October 2019 19
Icv Checking
November 2019 17