- 2

According to solution this is answer

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; while(number >0){ fact *= number-; } System.out.println(Fact); } }

14th May 2022, 3:10 PM
Aayan
7 Respostas
+ 3
And what is ***your question***?
14th May 2022, 3:17 PM
Lisa
Lisa - avatar
+ 4
What is your question and why did you tag "C++"?
14th May 2022, 3:12 PM
Lisa
Lisa - avatar
+ 2
For your math class you need a program to calculate the factorial of a number. You're given a program which takes a number as input. Task Complete the program to calculate the factorial of the given number and output it. Sample input 6 Sample output 720 Explanation The factorial of a number is equal to the product of all numbers less than or equal to the given number. The factorial of 6 will be 6*5*4*3*2*1 = 720. Hint Use while loop to calculate the factorial of the number. While loops
14th May 2022, 5:51 PM
BroFar
BroFar - avatar
+ 2
If your question is something like: "What's not working with my code?" * decrement would be number--, not number- * in the output you have a typo: it's fact, not Fact
14th May 2022, 5:54 PM
Lisa
Lisa - avatar
+ 1
Lisa java LESSON 16 .2
14th May 2022, 3:16 PM
Aayan
+ 1
Lisa **this have in question
14th May 2022, 3:20 PM
Aayan
+ 1
Lisa thanks for answer This is answer 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; while(number >0){ fact *= number--; } System.out.println(fact); } }
15th May 2022, 8:47 AM
Aayan