range

java - switch statement with range of int

最后都变了- 提交于 2019-12-05 05:24:42
I want to use a switch statement to check a range of numbers I have found a few places saying something like case 1...5 or case (score >= 120) && (score <=125) would work but I just somehow keep on getting errors. What I want is if the number is between 1600-1699 then do something. I can do if statements but figured it's time to start using switch if possible. On the JVM level switch statement is fundamentally different from if statements. Switch is about compile time constants that have to be all specified at compile time, so that javac compiler produces efficient bytecode. In Java switch

Excel SortFields add then sort

扶醉桌前 提交于 2019-12-05 04:49:30
问题 Would you help me understand this snippset: First, it seems that a sorting rule is added with MainSheet.Sort.SortFields.Clear For lI = 1 To vSortKeys(0, 1) MainSheet.Sort.SortFields.Add Key:=Range(vSortKeys(lI, 1) & 2), SortOn:=xlSortOnValues, Order:=vSortKeys(lI, 2), DataOption:=xlSortNormal Next Then, I understand that the following code is effectively running the sort With MainSheet.Sort .SetRange Range("A" & lFrom & ":" & GEN_REV_END & lTo) .Header = xlNo .MatchCase = False .Orientation =

HTTP: How should I respond to “Range: bytes=” when Range is unsupported?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 04:40:17
What is the correct response to a GET request with the header field Range: bytes=278528- if Range is not supported? Reading the HTTP header definitions ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html ) i think i should at least set: Accept-Ranges: none , but it clearly states that Clients MAY generate byte-range requests without having received this header for the resource involved. So, if a client requests a range, should I: Reply with the whole file from byte 0? Reply with some status error? (400/406/416/501) see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html You may ignore

Creating a PostgreSQL `tsrange` from two timestamps

怎甘沉沦 提交于 2019-12-05 02:50:49
问题 I am trying to create a tsrange (last Thursday to the previous Thursday) in a postgresql query but I get cast errors. This is what I have got so far (starting off from this SO question). WITH past_week AS ( SELECT date_trunc('day', NOW() + (s::TEXT || ' day')::INTERVAL)::TIMESTAMP(0) AS day FROM generate_series(-7, 0, 1) AS s) SELECT ( date_trunc('day', (SELECT day FROM past_week WHERE EXTRACT(DOW FROM day) = '4') - '7 day'::INTERVAL), date_trunc('day', (SELECT day FROM past_week WHERE

Iterate over an infinite sequence in Ruby

天涯浪子 提交于 2019-12-05 02:03:37
I am trying to solve Project Euler problem #12: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the first triangle number to have over five hundred divisors? Here's the solution that I came up

Mysql range check instead of index usage on inner join

自闭症网瘾萝莉.ら 提交于 2019-12-05 01:41:39
I'm having a serious problem with MySQL (innoDB) 5.0. A very simple SQL query is executed with a very unexpected query plan. The query: SELECT SQL_NO_CACHE mbCategory.* FROM MBCategory mbCategory INNER JOIN ResourcePermission as rp ON rp.primKey = mbCategory.categoryId where mbCategory.groupId = 12345 AND mbCategory.parentCategoryId = 0 limit 20; MBCategory - contains 216583 rows ResourcePermission - contains 3098354 rows. In MBCategory I've multiple indexes (columns order as in index): Primary (categoryId) A (groupId,parentCategoryId,categoryId) B (groupId,parentCategoryId) In

Save Selected Text Range for Use Later Not working

巧了我就是萌 提交于 2019-12-05 01:32:44
问题 I am using contenteditable and highlighting some text. I want to then backup that text range, and at a later time give that range(text) a different color. If I check in my zss_editor.restorerange method I do get back a valid selection object, so it must be something incorrect in how I am previously saving that range. var zss_editor = {}; // The current selection zss_editor.currentSelection; zss_editor.backuprange = function(){ var selection = window.getSelection(); zss_editor.currentSelection

Keep text selected when focus input

感情迁移 提交于 2019-12-05 00:54:30
This question has already been asked but until now there is no working answer so I am tempting to open it again hopefully we can find a hack to it. I have a contentEditable paragraph and a text input, when I select some text and click the input, the selection is gone. So I've tried to save the selection on input mousedown and to restore it back on mouseup and yeah it works ( as expected in firefox) But... in chrome the input lose focus :( See it in action ( use chrome ) : https://jsfiddle.net/mody5/noygdhdu/ this is the code I've used : HTML <p contenteditable="true"> Select something up here

Generate random numbers in specified range - various cases (int, float, inclusive, exclusive)

不羁岁月 提交于 2019-12-05 00:07:41
given a Math.random() function which returns a number between [0,1) and min max values to specify the range, how can we generate numbers for the following cases: Case we want integer : A: (min,max) ? B: [min,max) return Math.floor(Math.random() * (max - min)) + min; C: (min,max] ? D: [min,max] return Math.floor(Math.random() * (max - min + 1)) + min; Case we want float : A: (min,max) ? B: [min,max) return Math.random() * (max - min) + min; C: (min,max] ? D: [min,max] ? Integers Your formula for B. is correct, everything else is obtained by trivial +1 -1 corrections: A. (min, max) = [min + 1,

Explain this code in K&R 2-1

ぐ巨炮叔叔 提交于 2019-12-04 23:55:26
I'm trying to determine range of the various floating-point types. When I read this code: #include <stdio.h> main() { float fl, fltest, last; double dbl, dbltest, dblast; fl = 0.0; fltest = 0.0; while (fl == 0.0) { last = fltest; fltest = fltest + 1111e28; fl = (fl + fltest) - fltest; } printf("Maximum range of float variable: %e\n", last); dbl = 0.0; dbltest = 0.0; while (dbl == 0.0) { dblast = dbltest; dbltest = dbltest + 1111e297; dbl = (dbl + dbltest) - dbltest; } printf("Maximum range of double variable: %e\n", dblast); return 0; } I don't understand why author added 1111e28 at fltest