我一直在尝试调试这段代码,但似乎无法弄清楚为什么即使满足条件(例如findTitle.equals(title)); 它仍然会转移到'其他'状态.一切看起来很直接,似乎是正确的.有什么见解吗?
private void addNewMs() {
// TODO Auto-generated method stub
String title = Helper.readString("Enter movie title > ");
String theatre = Helper.readString("Enter theatre name > ");
Theatre Art = null;
for (int i = 0; i < movies.size(); i++){
String findTitle = movies.get(i).getTitle();
if (findTitle.equals(title)){
for (int a = 0; a < theatres.size();a++){
String findTheatre = theatres.get(a).getName();
if (findTheatre.equals(theatre)){
Art = theatres.get(a);
Movie m = movies.get(i);
int year = Helper.readInt("Enter year > ");
int month = Helper.readInt("Enter month > …Run Code Online (Sandbox Code Playgroud) 我正在编写CUDA程序,将模糊效果添加到BMP文件中.我编写了在CPU上执行此操作的程序,现在我正在尝试将代码转换为CUDA.这是我想要在CUDA上工作的功能:
void blur(bitmap_header* hp, unsigned char *data)
{
int xx,yy,x,y, avgB, avgG, avgR, ile;
int blurSize = 5;
for(xx = 0; xx < hp->width; xx++)
{
for(yy = 0; yy < hp->height; yy++)
{
avgB = avgG = avgR = 0;
ile = 0;
for(x = xx; x < hp->width && x < xx + blurSize; x++)
{
for(y = yy; y < hp->height && y < yy + blurSize; y++)
{
avgB += data[x*3 + y*hp->width*3 + 0];
avgG …Run Code Online (Sandbox Code Playgroud) 我的示例字典是:
sample_dict = {
'company': {
'employee': {
'name': [
{'explore': ["noname"],
'valid': ["john","tom"],
'boundary': ["aaaaaaaaaa"],
'negative': ["$"]}],
'age': [
{'explore': [200],
'valid': [20,30],
'boundary': [1,99],
'negative': [-1,100]}],
'others':{
'grade':[
{'explore': ["star"],
'valid': ["A","B"],
'boundary': ["C"],
'negative': ["AB"]}]}
}
}}
Run Code Online (Sandbox Code Playgroud)
它是一个“后续”问题 ->拆分 python 字典以生成所有值组合
我想得到一个隔离的组合列表,如下所示
有效组合:[仅从有效数据列表中生成]
COMPLETE OUTPUT for VALID类别 :
{'company': {'employee': {'age': 20}, 'name': 'john', 'others': {'grade': 'A'}}}
{'company': {'employee': {'age': 20}, 'name': 'john', 'others': {'grade': 'B'}}}
{'company': {'employee': {'age': 20}, 'name': 'tom', 'others': {'grade': 'A'}}}
{'company': …Run Code Online (Sandbox Code Playgroud) 我的标准代码
class Bank < ApplicationRecord
has_one :address
accepts_nested_attributes_for :address
end
class Address < ApplicationRecord
belongs_to :bank
end
Run Code Online (Sandbox Code Playgroud)
我的控制器
def create
@bank = Bank.new(bank_params)
respond_to do |format|
if @bank.save
format.html { redirect_to @bank, notice: 'Bank was successfully created.' }
format.json { render :show, status: :created, location: @bank }
else
format.html { render :new }
format.json { render json: @bank.errors, status: :unprocessable_entity }
end
end
end
def bank_params
params.require(:bank).permit(:code, :currency, :name, :mobile_1, :mobile_2, :email, address_attributes: [:id, :name, :area, :pin_code, :city_id] )
end …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以在math.max中使用if语句.例如,如果你有一个像这样的对象:
public class Obj {
private int i;
private boolean b;
public void setInt(int newInt) {
this.i = newInt;
}
public void setBool(boolean newBool) {
this.b = newBool;
}
public int getInt() {
return this.i;
}
public boolean getIsTrue() {
return this.b;
}
}
Run Code Online (Sandbox Code Playgroud)
初始化2个新对象并定义所有值后,是否可以执行以下操作:
System.out.println(Math.max(if(obj1.getIsTrue()) {obj1.getInt()}, if (obj2.getIsTrue()) {obj2.getInt()}));
Run Code Online (Sandbox Code Playgroud)
我知道它可以通过数组和for循环来完成,所以我不会问它是否可能,只是可以以这种方式嵌套if语句.
我需要在Python中使用递归重写这段可怕的代码.嵌套的深度应该取决于函数rec的参数,但事实上我希望它是变量"a"的长度,即字符串.我很感激任何回应和线索如何处理这个问题.
def rec():
count=0
for i in range(len(letters)):
for j in range(i+1, len(letters)):
if letters[i]+letters[j] in a:
for k in range(j+1, len(letters)):
if letters[i]+letters[j]+letters[k] in a:
if letters[i]+letters[j]+letters[k]==a:
count+=1
else:
for l in range(k+1, len(letters)):
if letters[i]+letters[j]+letters[k]+letters[l]==a:
count+=1
return count
Run Code Online (Sandbox Code Playgroud) 我想将以下c代码转换为haskell代码,而不使用列表。它返回两个数字出现的次数对于给定的n,其中n满足n=(a*a)*(b*b*b)。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void) {
int n = 46656;
int i,j,counter=0,res=1;
int tr = sqrt(n);
for(i=1; i<=tr; i++) {
for(j=1; j<=tr; j++) {
res = (i*i) * (j*j*j) ;
if(res==n) {
counter=counter+1;
}
printf("%d\n",res);
}
}
printf("%d\n",counter);
}
Run Code Online (Sandbox Code Playgroud)
在循环方面,我设法在haskell中做了类似的事情,但仅是为了找到总和。我发现也很难在haskell中实现if部分和反部分(请参见c代码)。任何帮助,不胜感激!这也是我的haskell代码:
sumF :: (Int->Int)->Int->Int
sumF f 0 = 0
sumF f n = sumF f (n-1) + f n
sumF1n1n :: (Int->Int->Int)->Int->Int
sumF1n1n f 0 = 0
sumF1n1n f n = sumF1n1n f (n-1) …Run Code Online (Sandbox Code Playgroud) 是否可以创建像这样的数组:
Array
(
[Name] => John
[Last Name] => Doe
[Age] => 19
)
Run Code Online (Sandbox Code Playgroud)
从这样的嵌套数组中:
[1] => Array
(
[Name] => John
)
[2] => Array
(
[Last name] => Doe
)
[3] => Array
(
[Age] => 19
)
Run Code Online (Sandbox Code Playgroud)
进行循环时在数组中添加值时会创建嵌套数组
foreach ($users as $user) {
$users[] = array($user['title'] => $user['value']);
}
Run Code Online (Sandbox Code Playgroud) 我想制作一个嵌套字典,但我不知道为什么我没有得到我想要的结果
def stud(data):
empty_dic = {}
for line in data:
empty_dic[line["stud_num"]]={line[course]:line[marks]}
return empty_dic
data = [
{
"course": "asd",
"stud_num": "123",
"marks": 28
},
{
"course": "qrt",
"stud_num": "123",
"marks": 27
},
{
"course": "asd",
"stud_num": "124",
"marks": 30
},
{
"course": "zx",
"stud_num": "124",
"marks": 31
},
{
"course": "zx",
"stud_num": "123",
"marks": 28
}
]
Run Code Online (Sandbox Code Playgroud)
我的代码的输出是=>{"123":{"zx":28},"124":{"zx":31}}
我想要的输出是=>{"123":{"asd":28,"qrt":27,"zx":28},124:{"asd":30,"zx":31}}
我正在编写一个程序,其中一开始的值是 0,但在整个程序中使用它来跟踪“更改”,然后我想打印更改的总和,其余代码工作正常,但是由于某种原因,进入多个函数的变量不会保留更改并在打印时返回它们,但每次都返回 0
var = 0
def func1(var1):
for i in range(x):
for j in range(y):
if condition:
pass
elif condition:
func2(var1)
return var1
def func2(var2):
if condition:
pass
elif condition:
var2 += 1
return var2
func1(var)
print(var)
Run Code Online (Sandbox Code Playgroud) nested ×10
loops ×4
python ×4
dictionary ×2
if-statement ×2
java ×2
recursion ×2
arrays ×1
c ×1
combinations ×1
counter ×1
cuda ×1
for-loop ×1
function ×1
haskell ×1
permutation ×1
php ×1
variables ×1