i have been asked to create a program which will receive a number and take 1 away each loop until it reaches 0 and then output each number and multiply them
e.g if the user enters 5 the output should be
5*4*3*2*1=120
i tried the following with no luck
int factor = sc.nextInt();
int count = 0;
int total = factor;
StringBuilder answer = new StringBuilder();
answer.append(factor);
while(factor>0)
{
for(int i = factor; i >= 0; i--)
{
count++;
total = total*count;
total = total -1;
if(i==factor)
{
answer.append(" = ").append(total);
}
else
answer.append(" * ").append(String.valueOf(i));
}
}
int sanswer=Integer.parseInt(answer.toString());
return sanswer;
}