Pergunta de entrevista da empresa Cisco

Factorial?

Resposta da entrevista

Sigiloso

25 de fev. de 2012

package com.homeaway.omapi.dao.mybatis; public class Factorial { public int factiorailIter(int n){ int res = 1; if (n == 0){ return 1; } while (n > 0){ res *= n--; } return res; } public int factorialRec(int n){ if (n ==0){ return 1; } else { return n * factorialRec(n-1); } } public static void main (String[] args){ Factorial f = new Factorial(); System.out.println(f.factiorailIter(5)); System.out.println(f.factorialRec(5)); } }