Question
A Digital Puzzle: There is only one 10 - digit number that contains every digit 0 through 9 exactly once and has the property that
A Digital Puzzle: There is only one 10 - digit number that contains every digit 0 through 9 exactly once and has the property that each number formed from the leftmost j digits is divisible by j . For example, consider the number 9876543210. The number contains each digit once, the first digit 9 is divisible by 1 , the number 98 is divisible by 2, 987 is divisible by 3, 9876 is divisible by 4, 98765 is divisible by 5, and 987654 is divisible by 6. However, the number 9876543 is not divisible by 7. Note that 98765432 is divisible by 8, 987654321 is divisible by 9, a nd 9876543210 is divisible by 10, so this number fails only because 9876543 is not divisible by 7. Program Requirements: Write a simple Java program tha t does the following: 1. Write a method that prompts the user to enter a number and returns it ( the entered number ). Use the following header: public static long readInputNumber () 2. Write a method with the following header that returns true if the formal parameter input N umber is of exactly ten digits. public static boolean isTenDigit(long inputNumber) 3. Write a method with the following header that returns true if the formal parameter inputNumber contains each of the digits 0 through 9 exactly once, in any order. public static b oolean i s Unique (long inputNumber) 4. Write a method with the following header that returns the total number of d ivisions that can be performed (refer A Digital Puzzle section for the calculation details). For example, on input 9876543210 your function should report 9 divisions (only 9876543 fails); for 2159730648 the number of divisions is just 1; and for the number 3816547290 (and only this number) the result is 10 p ublic static int numDivisions (long inputNumber) p ublic static int numDivisions (long inputNumber) Write a main method ( public static void main(String[] args ) that does the following: a. read a number by calling readInputNumber method a n d store it in inputUserNumber variable b. Using isTenDigit method, c heck if input User Number consists of exactly 10 digits ; Otherwise, repeat steps 5a and 5 b until user enters a valid 10 - digit number c. Using isUnique method, c heck if the input User Number contains each of the digits 0 through 9 exactly once . Otherwise, r epea t steps 5 a and 5 c until the user enters a valid 10 - digit number that ha s each of the digits 0 - 9 exactly once. d. Using numDivisions method, f ind the number of divisions that can be performed. e. Display the following message to the user Press 1 to repeat/continue and 0 to stop. f. If user enters 1 then repea t steps 5 a 5 e . If user enter 0, display s a Thank you message and exit .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started