laialii

Metodo pegaMes

Mar 19th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. /*Crie uma classe que contenha um método chamado "pegaMes" que receba uma data em forato texto no padrão "dd/mm/aaaa" e retorne apenas o número inteiro referente a mês.
  2. Ex saída:
  3. Data fornecida: 12/11/2009
  4. Mês: 11
  5. */
  6. import javax.swing.JOptionPane;
  7. class Ex2Metodos{
  8.  
  9. public static void main(String args[]){
  10.     String[] aux = "";
  11.     aux = JOptionPane.showInputDialog("Forneca uma data dd/mm/aaaa");
  12.     JOptionPane.showMessageDialog("Data fornecida: " + aux + "\nMês: " + pegaMes(aux));
  13. }
  14. public static String[] pegaMes(String[] aux){
  15.     int[] mes = new int[2];
  16.     mes[1] = Integer.parseInt(aux[4]);
  17.     mes[2] = Integer.parseInt(aux[5]);
  18.     return (mes[2]);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment