For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
HI, Help me to write below query: To find the date of Sunday after the 3rd Wednesday for next 2 years Sunday after the 3rd Wednesday. The output will be like this Sunday after the 3rd Wednesday OCT-24 NOV-21 DEC-19 till next two years. Thanks!!
There is a problem with an array index handling in the example you provided, remember that indexing is 0 based. Anyway, here's a bit more straightforward version of your code:
int numOfMonth = 0; String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int[] daysOfMonths ={28, 30, 31}; while(numOfMonth < 12){ switch(numOfMonth){ case 1: System.out.println(months[numOfMonth] + " has " + daysOfMonths[0] + " Days."); break; case 3: case 5: case 8: case 10: System.out.println(months[numOfMonth] + " has " + daysOfMonths[1] + " Days."); break; case 0: case 2: case 4: case 6: case 7: case 9: case 11: System.out.println(months[numOfMonth] + " has " + daysOfMonths[2] + " Days."); } numOfMonth++; }
There are couple of other observations regarding this example I can offer - it is considered to be a better coding practice not to perform actions and boolean checks in the same expression, doing so makes code less readable. Hence probably the reason why you had an issue understanding were code goes wrong. Also, try to avoid creating excessive intermediate variables.