while-loop

How to sum up the resultes in a while loop while centain input will end the while loop?

北战南征 提交于 2019-12-12 02:25:48
问题 I have a situation in java; I would like to ask the user to put in some numbers & have a total of those numbers. However if the user enter a negative number it will end the loop; currently I have a while loop as below; double sum = 0; double Input = 0; System.out.println("Please enter the numbers (negative to end)") System.out.println("Enter a number"); Scanner kdb = new Scanner(System.in); Input = kdb.nextDouble(); while (Input > 0) { System.out.println("Enter an income"); Input = kdb

Java String New Line Loop

戏子无情 提交于 2019-12-12 02:14:49
问题 I wrote a method that loops through a string and adds '/n' to create a line length that was given in the parameters. That description is not the best but it's hard to describe so look at the code below. Thanks in advance! My Code: public static String lineLength(String str, int length){ int totalLength = 0; //total length of the document int lengthConst = 0; //constant value of the length for the loop int nLength = 0; // length of \n = 2 characters String work1, work2; //Strings to work with

php + replace text inside an array resulting from query

那年仲夏 提交于 2019-12-12 02:14:07
问题 this is my approach, with no success anyways, but maybe it gives you an idea of what both my code and coding skills are like, as well as what I am trying to achieve. $data1 = mysql_query("SELECT * from `todolist` WHERE date > '$today' ") or die(mysql_error()); $data1b = str_replace("text-to-be-replaced", "replaced-text", $data1); while($info1 = mysql_fetch_array( $data1b )) { Print "".$info1['thingtobedone'] . " with ".$info1['persontomeet'] . "<br />"; } Also, my approach is incorrect since

Make python repeat a string until Yes or yes is inputted

橙三吉。 提交于 2019-12-12 02:08:18
问题 Yes I know that there is already a post covering this, but when I read it, it didn't help so please don't mark this as a duplicate. I want to write a program that asks the user if they want advice and if they input "No" or "no" I want it to repeat the question and if they input "Yes" or "yes" I want it to print the advice. I want it to include a while loop I have tried to write it myself but I can't get it to work correctly. Anyone know? Code from the comment for 3.4 - def doQuestion(question

While loop in Matlab to increment a number

家住魔仙堡 提交于 2019-12-12 02:05:39
问题 I am new to Matlab and this should be a stupid question. So the thing i wanted to do is to increment a number if a variable is true, in which i would be using that number to in the for loop. let me give you an example. global var1; var1 = true; while (var1) var2 = 2; var2 = var2+1 for var3=1:var2 do something... end end so var2 should give me incremented number from 2 till the while loop is false . I have tried a lot but just not able to get it. could any one help me? thanks in advance.

JavaScript while loop get select option and hide option from other select boxes

左心房为你撑大大i 提交于 2019-12-12 02:03:47
问题 I'm trying to develop a football teamline function that will store up to 18 players (11 starting players and 7 subs) using a select box for each player. When a player is selected from one select box they should then be hidden in all the other select boxes to stop the user from being able to select the same player again. I've written a javascript/jquery function that does this but it is VERY long winded and I'm guessing that the best option to make it a lot more manageable would be to write a

Template class not looping with str_replace

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:59:41
问题 Well i have this set of codes <?php include "includes/config.php"; class template{ var $page; var $built; public $block = array(); function _start($tpl){ $this->page = $tpl; } function set_array($data){ $this->block[] = $data; } function _show(){ foreach($this->block as $k => $v){ foreach($v as $k1 => $v1){ //echo $k1."<br />"; //echo $v1."<br />"; $this->page = str_replace("{".$k1."}", $v1, $this->page); } } echo $this->page; } } $template = new template(); $file = "<html> <body> <p>{CAT}</p

Ordering by a selected column from database

岁酱吖の 提交于 2019-12-12 01:42:44
问题 I have the following table that is meant to show a win/loss record and to have rankings. I'm running into two issues with it though. First issue is that my rank <td> is not progressing like I want it to. What I mean by that is for each record that is looped and output, I want it to be numbered for. i.e.: 1 2 3, etc. The second part I cannot figure out is I want the person with the highest win total to be ranked the highest. I also want losses to be configured into that. So if someone is 5-0,

C# warning: “The variable is assigned but its value is never used”

允我心安 提交于 2019-12-12 01:39:01
问题 I am a first-timer learning C# and I just started writing my first program. I am currently running into a snag in one of my while loops. Normally I find that outside the loop my variables work like they should, but for some reason Visual Studio is giving me a warning saying that "The variable 'itemPrice' is assigned but its value is never used." How I can I get that warning to go away and avoid any kind of bad practices? using System; class Program { public static void Main() { // "whoa" <--

While loop Time complexity

本小妞迷上赌 提交于 2019-12-12 01:29:51
问题 I have an algorithm exam.. and am a bit not great in the loops time complexity :s I just started to get the basics of it.. I have this while loop i=2 while (i<n) { i=i*i x=x+1 } I believe that the solution must be like: (i) will run from 2 to 2 k where k = 2 i every time it execute the statement 1 time.. so 1+1+1+.. , this means 1*2 k and from here I can't continue.. the second question guys.. please recommend a site or sth that I can practice some more of these.. searched but didn't find :s