[Solved] Get closest (but higher) number in an array

Here’s a method using Array.forEach(): const number = 165; const candidates = [2, 42, 82, 122, 162, 202, 242, 282, 322, 362]; //looking for the lowest valid candidate, so start at infinity and work down let bestCandidate = Infinity; //only consider numbers higher than the target const higherCandidates = candidates.filter(candidate => candidate > number); //loop … Read more

[Solved] python,typeerror:cannot concatenate ‘str ‘and ‘float’ objects

You need to convert the calculated number into a string before performing string methods on it. This might help: (“Celcius is:” + str(celcius)) You could also use the following method if you do not want to convert float to string: (“Celcius is: {}”.format(celcius)) 0 solved python,typeerror:cannot concatenate ‘str ‘and ‘float’ objects

[Solved] Java – how do I iterate through this map so method my method returns a string [closed]

A loop won’t return the String you want this way, you need to create the String and, at every loop, concatenate a new one to it: public static String m(Map<String, String> mp) { Iterator<?> it = mp.entrySet().iterator(); String str = “{” + ” \”SomeAttribute\”: ” + “{“; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); … Read more

[Solved] Removing html tags in from a string in android [closed]

I use this function this way, public String removeTags(String in) { int index=0; int index2=0; while(index!=-1) { index = in.indexOf(“<“); index2 = in.indexOf(“>”, index); if(index!=-1 && index2!=-1) { in = in.substring(0, index).concat(in.substring(index2+1, in.length())); } } return in; } I tried to do that with the function replaceAll() using regular experssion, but never had a good … Read more

[Solved] how do I initialize 0 to both constructors? [closed]

Your code is correct for your teacher’s requirements so far. Constructors effectively create an Object. In this case you have 2 constructors VendingMachine() and VendingMachine(int cans) both of which in their respective code initialize tokenCount to 0. Walking through your Tester line by line VendingMachine machine = new VendingMachine(); This constructor creates a new VendingMachine … Read more

[Solved] Serializing in Json.net [closed]

There is no question here but I am assuming you want to serialize that json string into an object? Also I would at least post what you have tried and what errors you are receiving if any. This is per the JSON.net web site found here http://james.newtonking.com/pages/json-net.aspx string json = “<you json string>”; JObject o … Read more

[Solved] How does the === work in ruby? [duplicate]

Because String === ‘a’ is the same as String.===(‘a’), which calls Class#===, inherited from Module#=== to test whether the parameter inherits from the receiver module; and ‘a’ === String is the same as ‘a’.===(String), which calls String#===, inherited from Object#=== to test whether the parameter is equal to the receiver object. In other words, === … Read more

[Solved] Days remaining before birthday in php [duplicate]

Duplicate Date Difference in php on days? EDITED: $diff=$date-time();//time returns current time in seconds $days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day) $hours=round(($diff-$days*60*60*24)/(60*60)); Is this how you wanted? $birthday = “1977-9-10″; $cur_day = date(‘Y-m-d’); $cur_time_arr = explode(‘-‘,$cur_day); $birthday_arr = explode(‘-‘,$birthday); $cur_year_b_day = $cur_time_arr[0].”-“.$birthday_arr[1].”-“.$birthday_arr[2]; if(strtotime($cur_year_b_day) < time()) { echo “Birthday already passed this year”; } else { $diff=strtotime($cur_year_b_day)-time();//time returns current time in seconds … Read more

[Solved] find the number of every letters in a word [closed]

Try this: public static void main(String[] args) { String input = “YYYCZZZZGG”; Map<Character, Integer> map = new HashMap<Character, Integer>(); // Map // to store character and its frequency. for (int i = 0; i < input.length(); i++) { Integer count = map.get(input.charAt(i)); // if not in map if (count == null) map.put(input.charAt(i), 1); else map.put(input.charAt(i), … Read more

[Solved] Java Timer : I want to fade in and out for my picture but there are some error [closed]

Screen size you cat get without using JFrame’s instance: screen = Toolkit.getDefaultToolkit().getScreenSize(); Also after creating JFrame, add a component listener to update width, height on any resize: JFrame frame = new JFrame(“fade frame”); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { width = image.getWidth(frame); height = image.getHeight(frame); } }); solved Java Timer : I … Read more

[Solved] Create a word document, Swift [closed]

Unfortunately, it is nearly impossible to create a .docx file in Swift, given how complicated they are (you can see for yourself by changing the file extension on any old .docx file to .zip, which will reveal their inner structure). The next best thing is to simply create a .txt file, which can also be … Read more