Design a class **ArmNum** to check if a given number is an Armstrong number or not. A number is said to be Armstrong if the sum of its digits raised to the power of length of the number is equal to the number.

Example:

371 = 3^{3} + 7^{3} + 1^{3}

1634 = 1^{4} + 6^{4} + 3^{4} + 4^{4}

54748 = 5^{5} + 4^{5} + 7^{5} + 4^{5} + 8^{5}

Thus, 371, 1634 and 54748 are all examples of Armstrong numbers.

Some of the members of the class are given below:

**Class name:** **ArmNum****Data members/instance variables:**

n: to store the number.

l: to store the length of the number.**Methods/Member Functions:**

ArmNum(int num): parameterized constructor to initialize the data member n = num.

int sumPow(int i): returns the sum of each digit raised to the power of the length of the number using **recursive technique**. E.g. 34 will return 3^{2} + 4^{2} (as the length of the number is 2)

void isArmstrong(): checks whether the given number is an Armstrong number by invoking the function sumPow() and displays the result with an appropriate message.

Specify the class **ArmNum** giving details of the constructor, int sumPow(int) and void isArmstrong(). Define a **main()** function to create an object and call the functions accordingly to enable the task.

```
import java.io.*;
class ArmNum{
private int n;
private int l;
public ArmNum(int num){
n = num;
l = 0;
for(int i = n; i != 0; i /= 10)
l++;
}
public int sumPow(int i){
if(i < 10)
return (int)Math.pow(i, l);
return (int)Math.pow(i % 10, l) + sumPow(i / 10);
}
public void isArmstrong(){
if(n == sumPow(n))
System.out.println(n + " is an Armstrong number.");
else
System.out.println(n + " is not an Armstrong number.");
}
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("N = ");
int num = Integer.parseInt(br.readLine());
ArmNum obj = new ArmNum(num);
obj.isArmstrong();
}
}
```

Sir,can we do the prime number using recursive function this way?

import java.io.*;

class Prime

{

public static void main(String args[])throws IOException{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(“N = “);

int n = Integer.parseInt(br.readLine());

if(isPrime(n,2)==1)

System.out.println(n+” is prime”);

else

System.out.println(n+” is not prime”);

}

public static int isPrime(int num,int f)

{

if(num==2)

return 1;

else if(num % f == 0 && num > f)

return 0;

else if(num == f)

return 1;

else if(num<2)

return 0;

else{

f++;

return isPrime(num,f);

}

}

}

Yes, looks correct. Try with some sample inputs to verify.

Sir,can we do the prime number using recursive function this way?

import java.io.*;

class Prime

{

public static void main(String args[])throws IOException{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(“N = “);

int n = Integer.parseInt(br.readLine());

if(n f)

return 0;

else if(num == f)

return 1;

else{

f++;

return isPrime(num,f);

}

}

}

The first “if” condition is wrong: if(n f)

Sir,2 programs is given which states that :

1)WAP in Java to accept a string & print all the consecutive and repeated characters present in the string.

Sample Input: understanding computer science

Sample Output:

Consecutive characters:

d e r s s t

Repeated characters:

u n e r s t i c

2) WAP in Java to accept a number and check whether the number is prime or not by using recursive function

Here is the link to your program that displays consecutive and repeated characters in a string.

Here is a program to check for Emirp numbers that has a recursive mehod to check for prime numbers. Refer to that program to get access to that recursive method.

Sir,a program is given which states that

WAP in JAVA to accept a word in lower case and display the new word after removing all the repeated letters.

Sample Input : applications

Sample Output : aplictons

Here is the program to remove repeated characters from a given string:

https://www.happycompiler.com/remove-repeated-letters-string/