You need a flag inside the loop to determine if it's the first factor eg
int cnt;
boolean isFirstFactor = true;
for (int i = 2; i <= n; i++) {
cnt = 0;
while (n%i == 0) {
cnt++;
n /= i;
}
if (cnt == 0)
continue;
if (isFirstFactor)
isFirstFactor = false;
else
System.out.print(" * ");
System.out.print(i + "^" + cnt);
}