Advertisement
brilliant_moves

MultiplesChecker.java

Sep 16th, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.61 KB | None | 0 0
  1. import java.util.Scanner; // for user input
  2.  
  3. public class MultiplesChecker {
  4.  
  5.     /**
  6.     *   Program:    MultiplesChecker.java
  7.     *   Purpose:    Yahoo! Answers
  8.     *   creator:    Chris Clarke
  9.     *   Created:    16.09.2013
  10.     */
  11.  
  12.     public static void main(String[] args) {
  13.  
  14.         Scanner scan = new Scanner(System.in);
  15.  
  16.         System.out.println("This program will collect a number from the user,");
  17.         System.out.println("and then report back the following:");
  18.         System.out.println("If the number is a multiple of 2 (2/N)");
  19.         System.out.println("If the number is a multiple of 3 (3/N)");
  20.         System.out.println("If the number is a multiple of 5 (5/N)");
  21.         System.out.println("If the number is a multiple of 7 (7/N)");
  22.         System.out.print("Where we see [The Number]:[Mult of 2]:[Mult of 3]");
  23.         System.out.println(":[Mult of 5]:[Mult of 7]");
  24.         System.out.println("(all the values should be separated by colons)");
  25.         System.out.println("For example, 21, which is a multiple of 3 and 7");
  26.         System.out.println("would be formatted like this:");
  27.         System.out.println("21:N:3:N:7");
  28.         System.out.print("What number would you like to test? ");
  29.  
  30.         int number = scan.nextInt(); // get integer from user
  31.  
  32.         System.out.print(number);
  33.         System.out.print(getMult(number, 2));
  34.         System.out.print(getMult(number, 3));
  35.         System.out.print(getMult(number, 5));
  36.         System.out.print(getMult(number, 7));
  37.  
  38.         System.out.println(); // new line
  39.  
  40.     }//end main()
  41.  
  42.     public static String getMult(int n, int a) {
  43.         // modulo (%) is the remainder after division
  44.         if (n % a == 0) {
  45.             return ":"+a;
  46.         } else {
  47.             return ":N";
  48.         }//end if/else
  49.     }//end getMult()
  50. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement