#include Title: Ask 1+2+...+n, do not use multiplication, for, while, if, else, switch, case, and other keywords and conditional judgment statement (A? B:C)
Method 1: Recursive, using logic and short-circuit characteristics Public class Solution { int sum_solution (int n) { int ans = n; (ans + = sum_solution (n-1)) ; return ans; }}Act 2. Calling Java library functions Public class Solution { publicint sum_solution (int n) { int Sum = ( C10>int) (Math.pow (n,2) + n); return sum>>1;} }Ask for 1+2+3+...+n, the request cannot use multiplication method, for, while, if, else, switch,
]: example 10:47:40> SHOW profile cpu,block io io for query 2; Let's take a look at the IO consumption in two SQL execution, the difference is "sorting result", we returnLook at the comparison of the previous execution plan, the timing of the two solutions to filter the data is not the same, the sorting needs to takeThe amount of data one is 20000, one is 20, exactly with the profile information here, the first solutionThe IO value of "sorting result" is nearly 500 times times the second solutio
This afternoon colleagues asked me a more basic question, when splicing SQL statements, if encountered like the situation what to do.My original writing is a simple concatenation of strings, and later colleagues asked me what to do if I encountered SQL injection. I think about it, it's really a problem.Just on the Internet to find the relevant instructions, the original is so written.As such an SQL statement: Select * from where like ' % Zhang San%
1. IF ELSEcannot be used in select, only blocks, such as:IF ...BEGIN...ENDelse (note that there is no else if, to be implemented can only be judged in the following block)BEGIN...ENDReference: Https://msdn.microsoft.com/en-us/library/ms182587.aspx2. Case and then ELSE ENDCan be used in select, but include end endCase ...When ... Then ...ELSE ... (can be omitted)ENDReference: Https://msdn.microsoft.com/en-us/library/ms181765.aspxSQL Server Judgment
intuitive to say----------------------------------------------------------------------------------------Then, let's experiment with the time spent on both of these methods.----------------------------------------------------------------------------------------typedef void (^nslogtime) ();Time spent viewing code in Nslogtime-(void) log: (nslogtime) log{ if (log) { Cfabsolutetime start = Cfabsolutetimegetcurrent (); Log (); Cfabsolutetime end__ = Cfabsolutetimegetcurrent (
pattern 1;;......Mode 2)The action performed when the value of the variable matches the pattern 2;;......Mode 3)The action performed when the value of the variable matches the pattern 3;;......*)The action performed when the value of the variable does not match any of the above modes;......EsacCases:#!/bin/bashRead-p "Please enter the letter of your choice a | B | C | D "ZimuCase $zimu inAecho "You entered the letter a";;Becho "You entered the letter B";;Cecho "You typed the letter C";;Decho "Y
to guess is:"$sumSleep 1Echo "Please enter a number between 1-50 and start guessing!"Count=0functiontype_num () {Read-P"Please enter a number:"NExpr$n +1>/dev/NULL if[$?-ne0]; Then Echo "Please enter a number"type_numfi}functionguess () {(Count++ )) if[$n-eq $sum]; Then Echo "you guessed it, your number is:"${count}if[$count-lt3]; Then Echo "you're so awesome." elif[$count-ge3-A $count-lt6]; Then Echo "It's still good, come on ." Else
The Switch...case statement in Swift can determine the object type, and the objective-c must be an integer.Can not penetrate, can not write break,
var rank = "A"
switch rank{case
"a"://equivalent to if
print ("excellent") Case
"B"://equivalent to else if
print ("excellent")
First, Select case syntax and parameter introduction
Select Case testexpression
[Case Expressionlist-n
[Statements-n]] ...
[Case Else
[Elsestatements]]
End Select
The syntax for the Select case statement has the following s
statement syntax
The code is as follows
Copy Code
case [Expression]When Condition_1 THEN result_1When Condition_2 THEN result_2...When Condition_n THEN result_nELSE resultEnd
expression is optional. It's worth the list of conditions that you compare. (ie: condition_1,condition_2, ... condition_n)
Condition_1 to Condition_n must be of the same data type. The order that
The Linux shell has its own process Control statement, which includes a conditional statement (if), a looping statement (For,while), and a SELECT statement (case). I'll use the example below to illustrate how each statement is use
Case statement Syntax:--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' END--case search function Case if sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then ' women ' else ' other ' ENDFirst, create a users table that contains Id,name,se
And then we're going to talk about the MySQL Tutorial stored procedure Case statement syntax and example tutorial Oh, home page let's look at a brief description of the case statement, and then illustrate the specific usage of the cases with an example.
Case
Case statements are useful for applications where multiple branches are required.The case Branch statement is formatted as follows:Case variable name inMode 1)Command sequence 1;;Mode 2)Command Sequence 2;;*)Sequence of commands executed by defaultEsacThe structure characteristics of case
Label:This period of time, do the project to do tired, finally a bit of personal study time, use this hour, summed up, the most recent time to do statistics when the case statement it. Structure: Case when ... then ... end 1. Change the value of the judgment at the same time eg Select Operatoraccount, Case when Create
Case ... Esac is similar to the switch ... case statement in other languages, and is a multi-branch selection structure.The case statement matches a value or a pattern, and if the match succeeds, the matching command is executed. The cas
Case ... Esac is similar to the switch ... case statement in other languages, and is a multi-branch selection structure.The case statement matches a value or a pattern, and if the match succeeds, the matching command is executed. The cas
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.