What is the problem in myArmstrong number code

Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans = 0;

	int count = 0;
	while (n % 10 != 0) {
		n = n / 10;
		count++;
	}

	while (n % 10 != 0) {
		int rem = n % 10;
		n = n / 10;
		ans = (int)(ans + (Math.pow(rem, count)));
	}
	if(n == ans) {
		System.out.println("true");
	}else {
		System.out.println("false");
	}

here is your updated code:


create a copy of n to compare later
if this solves your doubt please mark it as resolved :slight_smile: