我想使用递归方法但是无法使其正常工作.
例如,在这个程序中,为什么当我显示我的时候b,值是0而不是10?
public static void main(String[] args) {
int a = 0;
int b = recursivMethod(a);
System.out.println(b);
}
static int recursivMethod(int a)
{
if(a != 10)
recursivMethod(a+1);
return a;
}
Run Code Online (Sandbox Code Playgroud) 我希望比较两个列表,一个列表包含普通数据,第二个列表包含正则表达式并返回匹配项
例如
list1 = ['linux','6.0.1','mysql','5','abcd1234']
list2 = ['linux.*','6.*','mysql|python|gvim','5|6','abcd1234|efgh5678|ijkl91011']
Run Code Online (Sandbox Code Playgroud)
我想迭代匹配list1的正则表达式list2(在上面的情况下是正确的)
或者有比列表更好的方法吗?if/elif 是可能的,但很混乱
当我在aepub阅读器中运行搜索功能时,我的应用程序崩溃了.它以索引方法进入cellfor行,当它执行NSLOg(@"%@",hit.neighbourText)时显示异常.
(UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.adjustsFontSizeToFitWidth = YES;
NSLog(@"indexpath%d",indexPath.row);
NSLog(@"%@",[results objectAtIndex:[indexPath row]]);
hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
if([results count]>0) {
NSLog(@"%@",hit.neighboringText);
cell.textLabel.text = [NSString stringWithFormat:@"...%@...", hit.neighboringText];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Chapter %d - page %d", hit.chapterIndex, hit.pageIndex+1];
return cell;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了一些价值,hit.neighboringText但在那之后,我重新加载我的tableview然后会引发以下异常,为什么?
由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [__ NSCFConstantString neighborText]:无法识别的选择器发送到实例0x1481c4'***第一次抛出调用堆栈:
您好我正在尝试从3个不同的类别中选择10x3随机ID,但有没有更聪明的方法来实现这一点只需一个查询而不是3个不同的查询?
$sql = "SELECT id FROM rating WHERE category IN (1) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
$arr;
while ($obj = $result1->fetch_object()) {
$arr[] = $obj->id;
}
$sql = "SELECT id FROM rating WHERE category IN (2) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
while ($obj = $result1->fetch_object()) {
$arr[] = $obj->id;
}
$sql = "SELECT id FROM rating WHERE category IN (3) ORDER BY RAND() LIMIT 10";
$result1 = $dbCon->query($sql);
while ($obj = $result1->fetch_object()) {
$arr[] …Run Code Online (Sandbox Code Playgroud) 我正在编写一个构建字典的脚本,我观察到一种奇怪的行为.
我将在下面用一个小例子来描述它.
def test_f(parameter):
parameter.update({'watermelon':'22'})
return parameter
fruits = {'apple':20, 'orange': 35, 'guava': 12}
new_fruits = test_f(fruits)
Run Code Online (Sandbox Code Playgroud)
简而言之,我有一个字典,我传递给一个函数,test_f.该函数将新字典附加到输入并返回它.我在一个名为的变量中捕获函数的输出new_fruits.然而,这也改变了原始变量fruits.
为什么原始变量会fruits发生变化?我update是以错误的方式使用该方法吗?
要为api连接生成身份验证标头,我的代码应遵循以下步骤:
据我所知,php 中的字符串是字节数组,所以我的初始方法如下所示.
public function generateAuthKey()
{
$unique = uniqid(); # unique string
$string = $unique.':'.$this->apiKey; # step 1
$string = utf8_encode($string); # step 2 ?
$hash = hash('sha256', $string); # step 3
$base64 = base64_encode($hash); # step 4
return $base64;
}
Run Code Online (Sandbox Code Playgroud)
尝试使用此身份验证密钥进行连接的应用程序将收到403错误.
上面的代码是否完成了所需的步骤(也许我的api密钥中有错误)或者是否有其他方式在php中按照创建auth密钥的步骤进行操作?
是否有一种防水方法可以阻止在浏览器中禁用JavaScript的用户?
如果我检查cookie,用户可以手动添加cookie.
我需要进行此检查,因为即使禁用JavaScript,也应始终显示JavaScript JQuery弹出窗口.
php ×2
python ×2
dictionary ×1
function ×1
ios ×1
java ×1
javascript ×1
mysql ×1
objective-c ×1
sql ×1
uitableview ×1