if-statement

Java: while loop not working

我的梦境 提交于 2020-01-30 13:26:09
问题 I want to check the users input when a new game is created, and see if it is y, n, or neither. For some reason it skips the while loop all together and just outputs "Welcome to Questions." import java.util.Scanner; public class Questions { public static final Scanner INPUT = new Scanner(System.in); private boolean ans; public Questions() { while (ans = false) { System.out.print("Do you want to start a new game (y/n)?: "); String input = INPUT.nextLine(); if (input == "y"){ ans = true; //some

C# if/else first statement working, the rest are not

谁都会走 提交于 2020-01-30 12:29:44
问题 I know this is probably very basic, and I googled it and have gone through the search, but I'm having an issue which a very basic if/else scenario. The first statement produces results, which tells me that I've messed up the other statements somehow. It's driving me a little crazy. FYI, this is my first experience with a form window. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using

Conditional query with PDO prepare and bind statement

☆樱花仙子☆ 提交于 2020-01-30 12:19:06
问题 I am converting all my queries from mysql to PDO, and in this process I found a conditional query like a follows if (isset($parameters['searchTerm'])) { $where =" And title LIKE '%{$parameters['searchTerm'] }%'"; } $sql = "Select * from table data Where tableId = 5 {$where} "; and when I am trying to convert this query in PDO the expected syntax is as follows if (isset($parameters['searchTerm'])) { $where =" And title LIKE :searchTerm"; } $sql = $dbh->prepare("Select * from table data Where

ifelse over each element of a vector

隐身守侯 提交于 2020-01-30 12:11:49
问题 Looking at this post, I thought ifelse is vectorized in the sense that f(c(x1, x2, x3)) = c(f(x1), f(x2), f(x3)) . So, I thought if the code for z1 (provided below) will perform the following for each element of the vector y : Test whether it is unity or not. If YES , draw a random number from {1, 3, 5, 7, 9}. If NO , draw a random number from {0, 2, 4, 6, 8}. But, unfortunately it doesn't do that. It generates once for each case, and returns that very random number always. Where exactly am I

Bash comparison between strings - equal but not equal for it

喜你入骨 提交于 2020-01-30 11:47:45
问题 I just wanted to do a really simple comparison between 2 strings in Bash : stat=`curl -Is $url | head -n 1` echo $stat if [ "$stat" = "HTTP/1.1 200 OK" ];then echo "$symbol is OK" echo $stat valide=$(( $valide + 1 )) else echo "$symbol is 404" echo $stat err=$(( $err + 1 )) fi But even if "stat" is completely the same, the result stay that it does not equal : HTTP/1.1 200 OK AAA is 404 HTTP/1.1 200 OK How can i modify my code ? I had also a lot of errors with "/" ("unexpected operator", ...)

How to use if exists- if not exists in PL/SQL?

混江龙づ霸主 提交于 2020-01-30 11:31:47
问题 I am trying to convert if exists statement from SQL-Server to PL/SQL but having an error. I am trying to check if NAME_1 doesn't exist in my table_1 , if they don't exist then I am checking if COLUMN_NAME='NAME_2' exist in my table_1 , if it exist then insert (NAME_1 and NAME_2) into my table_2 . Thanks T-SQL (SQL-Server): IF NOT (EXISTS (SELECT * from table_name_1 where name='NAME_1')) BEGIN IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table_1' AND COLUMN_NAME=

“the condition has length > 1 and only the first element will be used” error

好久不见. 提交于 2020-01-30 10:52:09
问题 I have a problem with the f statement, because it's returning to me this error message : "the condition has length > 1 and only the first element will be used" I have a dataframe called data.summary, and I want to create two new variable vol.up and vol.down depending on the other variable of my dataframe. This is my script code : data.summary <- call.dat12[,c("Dur...ms.", "Handset.Manufacturer", "Src.Dst.Sig.Vol..Bytes.", "Dst.Src.Sig.Vol..Bytes.", "group", "Src.Node.Type", "Dst.Node.Type")]

ternary construction not equivalent with if then else

大憨熊 提交于 2020-01-30 08:48:05
问题 The following if/then test (in bash): if [ 1 ]; then ls /undef_dummy > /dev/null 2>&1; else echo "else stmt"; fi seems not equivalent to its ternary version: (test 1) && ls /undef_dummy > /dev/null 2>&1 || echo "else stmt" The first one will print nothing but the second one will print "else stmt". This is because the || operator in the ternary version relates to the return status of either the test or the command executed if the test passes. But usually, we want the else statement to only

Keypress event if NOT input

让人想犯罪 __ 提交于 2020-01-30 06:47:25
问题 I have the following jQuery events in my site $(window).keyup (function(event) { switch (event.keyCode) { case 68: // Alt-N = next scroll ('next'); break; case 65: // Alt-P = prev scroll ('prev'); break; } }); }); <script> $(document).keydown(function(e) { if(e.keyCode==68){ window.location.href = "{PreviousPost}"; } }); </script> I'm using window and document because they both work and searching didn't result in me finding out what the difference is in terms of functionality. But anyway,

javascript switch() or if()

99封情书 提交于 2020-01-28 02:29:23
问题 which would be better if i do this: if(message == 'redirect') { is_valid.accepted = true; } else if(message == 'invalid id') { is_valid.accepted = false; } else { is_valid.accepted = false; } or i do it this way switch (message) { case 'invalid id': default: is_valid.accepted = false; break; case 'redirect': is_valid.accepted = true; break; } 回答1: You might use switch if you foresaw needing to add lots of new cases. If you won't be adding many new cases, I might do, for clarity: is_valid