Question
A five-digit number is said to be friendly if: the leftmost digit is divisible by 1 and the leftmost two digits are divisible by 2
A five-digit number is said to be friendly if:
- the leftmost digit is divisible by 1 and
- the leftmost two digits are divisible by 2 and
- the leftmost 3 digits are divisible by 3 and
- the leftmost 4 digits are divisible by 4 and
- leftmost 5 digits (the five-digit number itself) is divisible by 5.
For example, the number 42325 is a friendly number:
- 4 is divisible by 1 and
- 42 is divisible by 2 and
- 423 is divisible by 3 and
- 4232 is divisible by 4 and
- 42325 is divisible by 5.
Write a program that will accept a 5 digit number (i.e, 10000 - 99999) from the user and prints to the screen a message telling the user if the number entered is or is not a friendly number. If the number entered is not a 5 digit number print to the screen an appropriate message and end the program. You must use an if/else statement which must have a condition constructed using boolean logic to test if the number is friendly.
Name your program Friendly_yourInitials.java where yourInitials represents yourinitials.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Friendly Number Checker FriendlyJBjava Java import ...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