+ 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

29th Jan 2022, 9:42 AM
Igaman Igaman
Igaman Igaman - avatar
3 Réponses
+ 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);
29th Jan 2022, 9:48 AM
Jayakrishna 🇮🇳
0
I want with while
29th Jan 2022, 10:04 AM
Igaman Igaman
Igaman Igaman - avatar
29th Jan 2022, 1:53 PM
Jayakrishna 🇮🇳