Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 01: An n-digit positive integer d1d2d3-.. dn-1 dn satisfies property A

ID: 3699647 • Letter: Q

Question

Question 01: An n-digit positive integer d1d2d3-.. dn-1 dn satisfies property A if the sum of the nth powers of its digits is equal to the number itself Examples of integers satisfying property A: 6-61 1634 14+ 64+ 3444 1531353 33 Write a Java program consisting of the main method and a private static boolean method that takes an integer and it returns true if the integer satisfies property A; otherwise it returns false. The main method prompts for and reads an integer, it then determines whether the integer satisfies property A or not by using the boolean method Note: . The boolean method must throw java.lang.lllegalArgumentException if it is passed an integer less than one . The main method must recover from both java.util.InputMismatchException and java.lang.lllegalArgumentException by looping until a valid value is entered The behaviour of your program must be similar to the program runs below: . Input a positive integer number to check if it satisfies property A: -2 java.lang. IllegalArgumentException: parameter less than 1 input a positive integer number to check I 1t 3atisties property A: five java.util.InputMismatchException Input a positive integer number to check if it satisfies property A: 153 The number 153 satisfies property A. Input a positive integer number to check if it satisfies property A: 1634 The number 1634 satisfies property A Input a positive integer number to check if it satisfies property A: 54748 The number 54748 satisfies property A Input a positive integer number to check if it satisfies property A: 123 The number 123 does not satisfy property A Input a positive integer number to check if it satisfies property A: 4 The number 4 satisfies property A

Explanation / Answer

import java.util.Scanner;

public class CheckPropertyA
{
public static void main(String args[])
{
int n;

Scanner in = new Scanner(System.in);
n = in.nextInt();
boolean check = CheckA(n);
System.out.println(check);
if(check==true){
System.out.println("The given number "+n+" "+"Satisifies Property A");
}
else{
System.out.println("The given number "+n+" "+"Doesn't Satisifies Property A");
}
  
}
private static boolean CheckA(int n){
int sum = 0, temp, remainder, digits = 0;
System.out.println("Input a number to check if it is satisfies Property A");   
  

temp = n;

// Count number of digits

while (temp != 0) {
digits++;
temp = temp/10;
}

temp = n;

while (temp != 0) {
remainder = temp%10;
sum = sum + power(remainder, digits);
temp = temp/10;
}

if (n == sum){
return true;}
else{
return false;}

}
public static int power(int n, int r) {
int c, p = 1;

for (c = 1; c <= r; c++)
p = p*n;

return p;
}
}

Note : please run the class in any ide or complier.....keep in mind that give same class as file name......if any doubts or queries just revert back me....Happy Coding!!!