fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.DateFormat;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.Locale;
  10. import static jdk.nashorn.internal.objects.NativeString.split;
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main(String[] args) throws Exception {
  15. Date data = new Date();
  16. Locale local = new Locale("pt", "BR");
  17. DateFormat formato = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", local);
  18. String novaData = formato.format(data);
  19. int dia = Integer.parseInt(novaData.substring(0, 2));
  20. System.out.println(getDiaPorExtenso(dia) + novaData.substring(2));
  21.  
  22. }
  23. public static String getDiaPorExtenso(int dia) throws Exception {
  24. String dias[] = {"zero", "um", "dois", "três","quatro", "cinco", "seis", "sete", "oito", "nove"};
  25. String retorno = "";
  26.  
  27. if (dia < 1 || dia > 31) {
  28. throw new Exception("Não existe esse dia em nenhum mês do ano");
  29. }
  30. else if (dia < 10) {
  31. retorno = dias[dia];
  32. }
  33. else if (dia < 20) {
  34. retorno = new String[]{
  35. "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove"
  36. }[dia - 10];
  37. }
  38. else if (dia < 30) {
  39. if (dia == 20) {
  40. retorno = "vinte";
  41. }
  42. else {
  43. retorno = "vinte e " + dias[dia - 20];
  44. }
  45. }
  46. else {
  47. if (dia == 30) {
  48. retorno = "trinta";
  49. }
  50. else {
  51. retorno = "trinta e " + dias[dia - 30];
  52. }
  53. }
  54.  
  55. return retorno.substring(0, 1).toUpperCase() + retorno.substring(1);
  56. }
  57. }
Success #stdin #stdout 0.15s 321408KB
stdin
Standard input is empty
stdout
Vinte e nove de Fevereiro de 2016