sexta-feira, 16 de março de 2007

megaSena java

Programinha Velhoooo, época de facul USJT

import javax.swing.JOptionPane;
public class megaSena{

public static void main(String args[]){

 
int iNumCartao;
 
int iDezenas[] = new int[6];
  String sCartao;

  sCartao = JOptionPane.showInputDialog(
"Quantidade de cartões: ");
  iNumCartao = Integer.parseInt(sCartao);

  sorteia(iDezenas);
  apresenta(iDezenas);

  System.exit(0);
}

public static void sorteia(int iVet[]){

 
for (int i = 0; i < 6; i++) { 
      iVet[i] = (int) (Math.random()*60+1);
  }
}

public static void apresenta(int iDezenas[]){

  String sOut =
"O valor digitado foi: ";
   for (int i=0; i < 6; i++){ 
       sOut = sOut + iDezenas[i]+ " ";
   }
  

 JOptionPane.showMessageDialog(null, sOut,"Cartão",  JOptionPane.PLAIN_MESSAGE);
}

}

calculaPotencia java

Época de Facul tb. Olddddd

import javax.swing.JOptionPane;
public class calculaPotencia {

public static void main(String args[]){

    //Declaração das variáveis
    int iVal1, iPot,iTotal;
    String sVal1, sValPot;

    // Armazenando e convertendo os valores
    sVal1 = JOptionPane.showInputDialog(null, "Adicione um valor:",     "Potência",JOptionPane.INFORMATION_MESSAGE);
    iVal1 = Integer.parseInt(sVal1);

    sValPot = JOptionPane.showInputDialog(null, "Adicione a potência","Potencia",JOptionPane.INFORMATION_MESSAGE);
    iPot = Integer.parseInt(sValPot);

    //Passando parametros para o método
    iTotal = calcPot(iVal1, iPot);

    //Imprimindo o resultado
    JOptionPane.showMessageDialog(null, "O número: " + iVal1 + "\nElevado a: " + iPot + "\nResulta : " + iTotal);

    System.exit(0);
}

    //Método que calcula a Potência
    public static int calcPot(int iV, int iP){


    int iT, iVal;
    iVal = iV;
    iT = 1;

    while (iP >= 1){
        iT = iT * iVal;
        iP--;
    }


    return iT;
   }
}