Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class ExemploFuncoes {
- public static int leNumero (String msg) {
- int n = Integer.parseInt(JOptionPane.showInputDialog(msg));
- while (n < 0 || n > 10)
- n =Integer.parseInt(JOptionPane.showInputDialog("Coloque um número de 0 até 10!\n" + msg));
- return n;
- }
- public static void exibe (String msg) {
- JOptionPane.showMessageDialog(null, msg);
- }
- public static int calculo(int numero,int i,int fatorial){
- for (i=1; i <= numero; i++){
- fatorial = fatorial * i;
- }
- return fatorial;
- }
- public static void main (String [] args){
- int fatorial=1, numero, i=1;
- numero = leNumero("Entre com numero desejado: ");
- fatorial = calculo(numero,i,fatorial);
- exibe("O fatorial é: "+fatorial);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement