while-loop

Find the first missing number in a sequence of numbers

谁说我不能喝 提交于 2019-12-02 16:31:45
问题 It's the second day I try to find a solution for this problem. I have an array. $datas; $datas[0]; // 8000 $datas[1]; // 8001 $datas[2]; // 8003 $datas[3]; // 8004 I have to find the first missing number starting from 8000 in this case it's 8002. My idea is to do somethig like this: $datas[0] +1 = $datas[1] if it's true port it's not free and I have to check the next one, if it's false it's the first free number. I know it's not a correct syntax but I have some problems writing it in the

python accumulating while loop keeps repeating what did i do wrong?

亡梦爱人 提交于 2019-12-02 16:27:22
问题 I can't figure out what I am doing wrong. I have tried using a break, and tried setting what the variable !=, I am doing this on cengage and it is very finnicky. """ LeftOrRight.py - This program calculates the total number of left-handed and right-handed students in a class. Input: L for left-handed; R for right handed; X to quit. Output: Prints the number of left-handed students and the number of right-handed students.""" rightTotal = 0 # Number of right-handed students. leftTotal = 0 #

While loop exiting before computation because of datatypes

泄露秘密 提交于 2019-12-02 15:53:07
问题 My program specifications are as follows. 1. All four digits are different 2. The digit in the thousands place is three times the digit in the tens place 3. The number is odd. 4. The sum of the digits is 27. I left out some code of the whole program. It has a clean compile but when it runs it automatically terminates. I think the problem lies somewhere in the conversion of the datatypes. int randomNumber = rand.nextInt(9000) + 1000; String randomString; boolean found = true; while (found) { /

while() loop for user input

ⅰ亾dé卋堺 提交于 2019-12-02 15:51:16
问题 I'm working on setting up a while() that executes until the user enters an integer. However, the way I have it now, the loop prints the message "Please enter an integer" again after the integer has been entered, and then the program executes normally. Can someone suggest a way to make not print that message again after an integer has been entered? Thanks! System.out.println("Enter word length"); if(in.hasNextInt()) { n = in.nextInt(); } else { while(in.hasNext()) //this is the loop i'm

GUI Freezes During While Loop in Java

我的梦境 提交于 2019-12-02 15:41:01
问题 http://i.stack.imgur.com/XvHm5.png When I click the On button it should start spamming 1's across the JTextField. Instead The entire GUI freezes, including the close button. I am using a while loop that will stop when you click the jButton again. Because the jButton is frozen i cannot stop this program. I have read that Threads and Multithreading would help but all of the tutorials are too complex for me to understand. They say to put the loop and GUI on different threads. I want to

javascript while loop giving different results in node and browser

时间秒杀一切 提交于 2019-12-02 15:31:28
问题 I am executing the following seemingly straightforward code var number = 0; while (number <= 12) { console.log(number); number = number + 2; } and I am getting different results in the browser and in Node. When I run it in the Firebug(v 2.0.4 ) console on Firefox(v. 32.0.3) the result I get is 0 2 4 6 8 10 12 14 which is not`the result I expected. In Node, the same code gives me the correct answer which is 0 2 4 6 8 10 12 Is there anything I'm missing regarding the behaviour in the browser???

Why is the following program stuck in a loop?

喜欢而已 提交于 2019-12-02 15:23:29
问题 I wrote a solution to an exercise that asks to write a program that acts as a simple "printing" calculator, and also detects division by zero and checks for unknown operators. The program works as intended when expected operators are entered. For example: "100 S" prints "= 100.000000" "2 /" prints "= 50.000000" "10 *" prints "= 500.000000" It also detects division by zero and unknown operators. However, when I enter operators in wrong order, like this: "/ 2" or "* 10", the program is stuck in

If/else proper indentation inside while loop [closed]

情到浓时终转凉″ 提交于 2019-12-02 15:06:22
I started learning programming with Python about a few weeks now and I am having some trouble. The following code is a tiny program that checks whether there's an even number in a list, if it finds the first even number, it breaks out of the loop: numbers = [1, 3, 5] position = 0 while position < len(numbers): number = numbers[position] if number % 2 == 0: print('Found even number', number) break position += 1 else: # break not called print('No even number found') That prints the error: File "test.py", line 11 else: # break not called ^ SyntaxError: invalid syntax That's an indentation issue,

Optimize while and SQL in foreach

时光总嘲笑我的痴心妄想 提交于 2019-12-02 14:53:15
My code : $text = '12-name-y-86'; $array = explode('-',$text); foreach($array as $value) { $sql = mysql_query("SELECT * FROM `table` WHERE `pid`='$value' ORDER BY `id` LIMIT 3"); echo '***'.$value.'***'; echo '<br />'; while($row = mysql_fetch_array($sql)) { echo $row['title']; echo '<br />'; } echo '<br /><br />'; } Print : 12 title1 title2 title3 name ti1 ti2 ti3 y tle1 tle2 tle3 86 mytitle1 mytitle2 mytitle3 This code work full buy for more values in $text , server has down ! Try to select all records in just one query, like this: $text = '12-name-y-86'; $array = explode('-', $text); $array

Matlab : Plot of entropy vs digitized code length

纵然是瞬间 提交于 2019-12-02 14:38:01
问题 [Tent Map][1] is a dynamical system that is discrete in time. Iterations of the map yields a time series. The entropy of this system when discretized in 0/1 using a threshold = 0.5 is, H = log_2(2) = 0.69 approx. I want to obtain a graph with Y Axis as the entropy and X Axis as the Number of samples or the length of the time series. I have written a code for obatining the entropy by varying the length of the time series. The objective is to see at what length of the discretized time series, I