Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // for user input
- public class MultiplesChecker {
- /**
- * Program: MultiplesChecker.java
- * Purpose: Yahoo! Answers
- * creator: Chris Clarke
- * Created: 16.09.2013
- */
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("This program will collect a number from the user,");
- System.out.println("and then report back the following:");
- System.out.println("If the number is a multiple of 2 (2/N)");
- System.out.println("If the number is a multiple of 3 (3/N)");
- System.out.println("If the number is a multiple of 5 (5/N)");
- System.out.println("If the number is a multiple of 7 (7/N)");
- System.out.print("Where we see [The Number]:[Mult of 2]:[Mult of 3]");
- System.out.println(":[Mult of 5]:[Mult of 7]");
- System.out.println("(all the values should be separated by colons)");
- System.out.println("For example, 21, which is a multiple of 3 and 7");
- System.out.println("would be formatted like this:");
- System.out.println("21:N:3:N:7");
- System.out.print("What number would you like to test? ");
- int number = scan.nextInt(); // get integer from user
- System.out.print(number);
- System.out.print(getMult(number, 2));
- System.out.print(getMult(number, 3));
- System.out.print(getMult(number, 5));
- System.out.print(getMult(number, 7));
- System.out.println(); // new line
- }//end main()
- public static String getMult(int n, int a) {
- // modulo (%) is the remainder after division
- if (n % a == 0) {
- return ":"+a;
- } else {
- return ":N";
- }//end if/else
- }//end getMult()
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement