+ 4
Why this code gives negative values for some input values??
import java.util.Scanner; public class product { public static void main (String [] args){ System.out.println("Enter a number = ") ; Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int i=1; long mul=1; while(i<=n){ mul=mul*i; i++; } System.out.println(mul); } } input=21 output=-4249290049419214848 why??
1 Answer