Skip to content

Instantly share code, notes, and snippets.

@chankruze
Last active October 9, 2024 11:16
Show Gist options
  • Save chankruze/cdebab82a6c956cba5380cb8f25d9a38 to your computer and use it in GitHub Desktop.
Save chankruze/cdebab82a6c956cba5380cb8f25d9a38 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
public class StrongNumber {
public static int factorial(int n) {
if (n < 1) return 1;
return n * factorial(n - 1);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
List<Integer> strongNumbers = new ArrayList<>();
int size = sc.nextInt();
int i = 0;
// loop until positive numbers of queue size are received
while (i < size) {
System.out.println("Enter number " + i + ": ");
int num = sc.nextInt();
if (num >= 0) {
i++;
int n = num;
int sum = 0;
// break the number to extract each digit
while (n > 0) {
int digit = n % 10;
// calculate factorial
int fact = factorial(digit);
// add to sum
sum += fact;
// update the number
n /= 10;
}
if (sum == num) {
strongNumbers.add(num);
}
} else {
System.out.println("Enter positive number only.");
}
}
System.out.print("Strong numbers are: ");
for (int strongNumber: strongNumbers) {
System.out.print(strongNumber + " ");
}
}
}
@chankruze
Copy link
Author

In the TCS NQT exam environment, the Java compiler was likely configured with flags that enforce stricter type checking and treat warnings as errors. Specifically, it might have used flags like:

-Xlint:unchecked - This flag enables warnings for unchecked operations, like using raw types.
-Werror - This flag treats all warnings as errors, preventing compilation if any warning occurs.

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment