Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class ExemploFuncoes {
  3.  
  4. public static int leNumero (String msg) {
  5. int n = Integer.parseInt(JOptionPane.showInputDialog(msg));
  6. while (n < 0 || n > 10)
  7. n =Integer.parseInt(JOptionPane.showInputDialog("Coloque um número de 0 até 10!\n" + msg));
  8. return n;
  9. }
  10.  
  11. public static void exibe (String msg) {
  12. JOptionPane.showMessageDialog(null, msg);
  13. }
  14.  
  15.  
  16.  
  17. public static int calculo(int numero,int i,int fatorial){
  18. for (i=1; i <= numero; i++){
  19. fatorial = fatorial * i;
  20. }
  21. return fatorial;
  22. }
  23.  
  24.  
  25. public static void main (String [] args){
  26. int fatorial=1, numero, i=1;
  27.  
  28. numero = leNumero("Entre com numero desejado: ");
  29. fatorial = calculo(numero,i,fatorial);
  30. exibe("O fatorial é: "+fatorial);
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement