+ 1
Java 16.2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number = scanner.nextInt(); int fact = 1; for (int i = 1; i <=number; i ++){ fact = fact*i; System.out.println(fact); } } How get last factorial number ? #java
3 Respostas
+ 1
Do you mean to only fact value?
Take print statement out of loop..
for (int i = 1; i <=number; i ++)
{
fact = fact*i;
}
System.out.println(fact);
//}
edit:
int i = 1;
while ( i <=number)
{
fact = fact*i;
i++;
}
System.out.println(fact);
0
I want with while
0
You can try by reading this once... Igaman Igaman
https://www.programiz.com/java-programming/do-while-loop