Jump to content

Java Questão


Diogo Mata

Recommended Posts

int meses[] = { 31, 28, 31, 30, 31, 30, 31, 31 ,30 ,31 ,30 ,31};

int dadosAnuais[] = { 44, 188, -1, 8, 41, 41, 3, 31, 4, 88, 8, 81, 84, 88, 38, 46, 66, -1, 66, 63, 44, 44, 68, 44, 14, 38, 61, 84, 41, 81, 46, 38, 83, 63, 84, 83, 13, 43, 11, 44, 64, 44, 84, 8, 84, 81, 43, 4, 68, 84, 86, 11, 18, 4, 48, 84, 46, 41, 64, 44, 44, 44, 46, 8, 44, 81, 61, 43, 44, 14, 41, 46, 16, 81, 84, 13, 66, 48, 18, 88, 31, 36, 6, 8, 68, 46, 34, 46, 68, 46, 11, 36, 33, 36, 44, 64, 34, 44, 61, -1, 88, 38, 46, 36, 44, 48, 14, 46, 44, 44, 46, 64, 41, 84, 43, 4, 4, -3, 64, 66, 34, 61, 18, 86, 14, 43, 33, 68, 44, 1, 84, 83, 63, 14, -3, 68, 31, 41, 86, 64, 61, 41, 84, 84, 68, 81, 88, 46, 44, 81, 41, 43, 48, 64, 46, -1, 88, 14, -2, 34, 48, 86, 11, 88, 31, -3, 43, 31, 44, 6, 88, -3, 46, 11, 48, 86, 41, 63, 34, 84, 66, 61, 34, 48, 84, -1, 88, 44, 34, 63, 66, 46, 41, 48, 41, 36, 8, 81, 38, 64, 68, 43, 64, 66, 43, 46, 31, 66, 6, 81, 81, 34, 81, 8, 64, 14, 61, 41, 61, 64, 34, 86, 41, 68, 66, 38, 84, 38, -2, 6, 4, 64, 81, 31, 86, 14, 48, 44, -1, 34, 46, 44, 18, 48, 81, 81, 44, 46, 84, 86, 46, 41, 33, 84, 41, 68, 18, 44, 64, 48, 44, -3, 64, 86, 44, -2, 44, 43, 16, 64, 46, 31, 84, 88, 86, 48, 86, 48, 88, 11, 16, 64, -1, 6, 31, 46, 11, 83, 4, -3, 48, 48, 11, 48, 41, 81, 44, 41, 43, 81, 16, 64, 34, 66, 44, 61, 64, 88, 48, 88, 46, 64, 86, 84, 81, 41, 88, 81, 66, -1, 48, 34, 68, 46,111, 16, 63, -2, 64, -3, 46, 68, 18, 44, 68, 88, 44, -1, 38, 48, 34, 6, 11, 44, 84, 34, 44, 46, 64, 86, 11, 38, 64, 61, 44, 46, 83, 41, 83, 81, 66, 43, 14, 66, 64 };

System.out.println("Opção errada. Tente novamente: \n"
                          + "    ________________________________________________ \n"
                        + "    | 1-Janeiro           2-Fevereiro               |\n"
                        + "    | 3-Março             4-Abril                   |\n"
                        + "    | 5-Maio              6-Junho                   |\n"
                        + "    | 7-Julho             8-Agosto                  |\n"
                        + "    | 9-Setembro          10-Outubro                |\n"
                        + "    |11-Novembro          12-Dezembro               |\n"
                        + "    |Digite -5 para observar as estatísticas anuais.|\n"
                        + "    |Digite -4 para terminar a execução do programa.|\n"
                        + "    |_______________________________________________|\n");
                  opcao=teclado.nextInt();

Sendo este array (dadosAnuais) um dado por dia queria saber como calculo o melhor dia e o pior dia de cada mês dizendo o dia do mês que foi o melhor e o pior dia

Edited by thoga31
GeSHi
Link to post
Share on other sites

Podias usar o GregorianCalendar para incrementares e decrementares dias, instancias com o data 1/1/2020 (por exemplo, neste ano seria irrelevante, penso eu que não sei muito sobre esse problema em concreto), percorrias o array em busca do melhor e pior registo, guardavas esses indices, incrementavas isso à data e depois farias um getTime do calendário.

Aconselho-te a veres isto:

https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html

https://stackoverflow.com/questions/1416909/adding-days-to-a-date

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.