numbers

JavaScript: \\d{4} RegExp allows more than 4 digits [duplicate]

醉酒当歌 提交于 2019-12-13 22:21:18
问题 This question already has answers here : Match whole string (3 answers) Closed last year . Have following validation for year value from text input: if (!year.match(new RegExp('\\d{4}'))){ ... } RegExp equals null if numeric of digits from 0 to 3. It's OK. In case 4 digits it returns value. It's OK. In case more than 4 digits it returns value again,that it's NOT OK . Documentation says {n} declaration means exact number,but works like: exact+ With such ugly validation it work's fine: if (

How do you generate a random number with equal probability using Math.random() in Java [duplicate]

泪湿孤枕 提交于 2019-12-13 19:16:01
问题 This question already has answers here : How do I generate random integers within a specific range in Java? (65 answers) Closed 6 years ago . I'm currently working through an exercise where I am required to generate a random number which can be one of 4 values. (note I'm only allowed to use Math.random()) 0 1 2 or 3 Currently I am using this: randno = (int) (Math.random()*4); // range 0-3 However, the outcome MUST have equal probability. My tests so far (although the method is lacking) shows

Custom filter with white space as thousands separator is not working

谁说我不能喝 提交于 2019-12-13 15:34:05
问题 I am trying to write a custom filter to filter numbers on the format xxx xxx,xxx in my application. This is the function I wrote so far: var formatNumber = function(input, fractionSeparator, thousandsSeparator, fractionSize) { fractionSeparator = fractionSeparator || ','; thousandsSeparator = thousandsSeparator || ' '; fractionSize = fractionSize || 3; var output = '', parts = []; input = input.toString(); parts = input.split("."); output = parts[0].replace(/(\d{3})/g, ""+ thousandsSeparator

How to get the length of a numbers fraction part?

不打扰是莪最后的温柔 提交于 2019-12-13 14:27:27
问题 How do I find out the length or the number of digits of the fraction part of a decimal number? I can see a few aproaches, e.g. with Strings like this one: public static int getNumberOfFractionDigits(Number number) { Double fractionPart = number.doubleValue() - number.longValue(); return fractionPart.toString().length() - 2; } But what is the best way to determine the length? I could imagine some problems if I use Strings, e.g. because the locale and number format may be different from system

converting-words-to-numbers-in-php II

若如初见. 提交于 2019-12-13 14:08:55
问题 There is a great function here Converting words to numbers in PHP from El Yobo. But I have the problem that the string must begin with a written number. How can convert e.g. "iPhone has two hundred and thirty thousand, seven hundred and eighty-three apps" ? The explained function: function wordsToNumber($data) { // Replace all number words with an equivalent numeric value $data = strtr( $data, array( 'zero' => '0', 'a' => '1', 'one' => '1', 'two' => '2', 'three' => '3', 'four' => '4', 'five'

C finding second largest number in an array

ぃ、小莉子 提交于 2019-12-13 13:34:24
问题 As the title says, I have to find the second largest number in an array and if every number in that array is equal I should write that it's -∞. I wrote this, could anyone check to see if I could perhaps optimize it a little better? This array is just an example, it should be x[1...n] but since I have to rewrite it to pseudocode I took that one as an example #include <stdio.h> int main() { int x[7]={90,90,78,41,21,27,35}; int i, max, secmax, y; secmax=0; max=x[0]; for(i=1;i<=7;i++) { if (x[i]

Java自学-集合框架 Collections

戏子无情 提交于 2019-12-13 12:17:11
Java集合框架 工具类Collections Collections是一个类,容器的工具类,就如同Arrays是数组的工具类 步骤 1 : 反转 reverse 使List中的数据发生翻转 package collection; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class TestCollection { public static void main(String[] args) { //初始化集合numbers List<Integer> numbers = new ArrayList<>(); for (int i = 0; i < 10; i++) { numbers.add(i); } System.out.println("集合中的数据:"); System.out.println(numbers); Collections.reverse(numbers); System.out.println("翻转后集合中的数据:"); System.out.println(numbers); } } 步骤 2 : 混淆 shuffle 混淆List中数据的顺序 package collection; import java.util

Grouping of elements of set with first n Natural numbers, excluding one arbitrary element, to give us a Sum equal to S

我们两清 提交于 2019-12-13 11:29:34
问题 Array with elements sorted in descending order - l ans=[] for t in l: if t<=S: S-=t ans.append(t) if S==0: break ans, Gives us list with selected elements. Please tell me whether it is satisfiable by all big numbers or not? 回答1: No it doesn't work for all cases: For example : S = 17 and l = [10,5,4,3] The answer and will be: ans = [10,5] and S = 2 (because it didn't get down to 0) But it could have been solved by: ans [10,4,3] 回答2: For n=8 and omitted element=2. This won't return the right

Java help: How to find largest number in scanned in file?

十年热恋 提交于 2019-12-13 11:15:17
问题 I need to find the sum, count of, number of evens, number of odds, largest, smallest, and average of the numbers of the scanned file. I've done everything except largest/smallest. When the program runs, the largest/smallest equals the count instead of producing the largest/smallest value the count encounters. EDIT: I understand that largest/smallest are being compared to count. I now understand that mistake. I don't understand how to find the smallest/largest value that count encounters. Here

use macro to convert number format to text in Excel

冷暖自知 提交于 2019-12-13 10:36:53
问题 I'ved created a macro in Excel that I use to convert column number format to Text so the number format does not change after copy/past from a text file: Sub ConvertBitColumn() ' ConvertBitColumn Macro ' This macro converts 3rd column of the worksheet to Text. Dim sht As Worksheet Set sht = ActiveSheet sht.Columns(2).NumberFormat = "@" End Sub The code works fine, but the column in questin shows some green at the left hand corner for some cells, is there a way to get rid of it, or it is normal