correctness

Correctness of Sakamoto's algorithm to find the day of week

…衆ロ難τιáo~ 提交于 2019-11-26 10:07:26
问题 I am using Sakamoto\'s algorithm to find out the day of week from a given date. Can anybody tell me the correctness of this algorithm? I just want this from 2000 to 2099. The algorithm from Wikipedia is given for reference. int dow(int y, int m, int d) { static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; y -= m < 3; return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; } 回答1: Well, you can tell just by looking at it that it is correct... Assuming that the t[] array is correct, which you can

When do I need to specify the JavaScript protocol?

给你一囗甜甜゛ 提交于 2019-11-26 03:58:20
问题 I was under the impression that I only need to specify the \"protocol\" when using JavaScript in URL attributes, such as in hrefs. Is this the only \"useful\" context for javascript: ? Sensible: <a href=\"javascript:alert(\'Hello\')\">World!</a> Silly: <form onsubmit=\"javascript:alert(\'oops!\')\"> Is this right? Or is there some obscure bug/use case I need to be aware of? 回答1: The javascript: pseudo-protocol on event handlers will be only ignored, you don't need it, the JavaScript engine

No-throw VirtualMachineError guarantees

吃可爱长大的小学妹 提交于 2019-11-26 02:38:33
问题 I\'ve come to Java from C++. In the C++ world we pay attention to exception safety, and note that mutators can provide different guarantees in the face of exceptions thrown by the mutator itself or a method it delegates to (minimum, strong, no-throw). Implementing a method that has a strong exception guarantee requires that some basic operations are guaranteed never to throw an exception. The JLS makes statements about which operations can throw which kinds of exceptions, but the