我们一直在学习循环和嵌套for循环.
我的问题;
为什么一旦增量结束,内部for循环中变量的值会重置?但是在外部for循环中,变量保持其值.
例如:
public class Factorial {
public static void main(String[] arguments){
for(int i = 0; i <10; i++){
for (int count=6; count < 18; count+=6){
System.out.println (count);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,程序运行10次,同时递增i并计数增量为18,但后来又回到6?每一次......有人可以解释为什么会这样吗?
c1离开循环(以及之后)之前的最后一个值是6.它是如何6的?该变量的最后一个已知值是5.
这是代码snipplet
int c1, c2;
for (c2 = 4; c2 <= 5; c2++)
{
for (c1 = 2; c1 <= 5; c1++)
{
System.out.println("#"+""+c1);
}
System.out.println(c2 + " " + c1);
}
System.out.println("\nLoop is done");
Run Code Online (Sandbox Code Playgroud) 我在server1上有原始查询,需要在服务器2上创建它。我能够创建View,但是在执行该视图时,在CASE语句中遇到错误,如下所示:
Error:
Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Qry1097'.
Msg 125, Level 15, State 4, Line 1
Case expressions may only be nested to level 10.
Run Code Online (Sandbox Code Playgroud)
查询:SELECT
ID, Forename, Surname,
Code, Description,
Grade, Dept,
Course, Title,
CASE WHEN Code IN ('VJ028') THEN 'FUNCTIONAL SKILLS - LEVEL 1 & LEVEL 2'
WHEN Code IN ('VE203', '22877C') THEN 'WRITING - LEVEL 2'
WHEN Code …Run Code Online (Sandbox Code Playgroud) 我正在研究一个使用python读取树莓派数字输入的项目.我想将其中一个按钮变成一个切换按钮,因为只要按下它就会在1和0之间切换一个值.一切都工作正常,除了部分:
if(a == 0.0):
a = 1.0
if(a == 1.0):
a = 0.0
Run Code Online (Sandbox Code Playgroud)
似乎这应该与其余的代码一起使用,只要按下按钮,值就会在1和0之间切换,但每次都打印为0.0,是否有人知道这是为什么?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
a = 0.0
b = 0.0
c = 0
while True:
if(GPIO.input(4) ==1 and c ==0):
print 'Button 1 Pressed'
if(a == 0.0):
a = 1.0
if(a == 1.0):
a = 0.0
c = 1
print a
if(GPIO.input(4) !=1):
c = 0
if(GPIO.input(24) ==0):
print 'Button 2 Pressed'
Run Code Online (Sandbox Code Playgroud) 有人可以提供一个示例或参考,该示例或参考提供一种使用Jackson库将嵌套JAVA对象转换为JSON输出的方法的方法。我没有转换平面JAVA对象的问题。但是,JSON库显示嵌套的对象名称和类型,而不是其子对象。我充分利用了http://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/中提供的相同代码。因此,我没有附加任何代码示例。
例如
// This is what I get
{
"fname":null,
"lname":null,
"addr":null
}
// This is what I need as output
{
"name":null,
"lname":null,
"addr":{
street:"mull",
"city":null,
"zip":0
}
}
Run Code Online (Sandbox Code Playgroud)
这是示例类对象:
import address;
public class id implements Serializable {
public String fname;
public String lname;
public address addr;
}
public class address implements Serializable {
public String street;
public String city;
public int zip;
}
Run Code Online (Sandbox Code Playgroud) 我无法获得JSON格式的一些报告结构数据(大约300个案例),我需要它,因此我可以将它弹出到d3树网络中.我找不到一个自动化转换的函数 - 大部分资源都使用聚类函数(例如hclust),但我的数据只是一个未加权的边列表,所以这些函数不起作用.有什么建议?谢谢!
数据源示例:
jobTitle reportsTo
CTO CEO
CPO CEO
Director CPO
Manager Director
Run Code Online (Sandbox Code Playgroud)
需要JSON输出:
"name": "CEO",
"children": [
{
"name": "CPO",
"children": [
{
"name": "Director",
"children": [
{
"name": "Manager",
"children": []
}
]
}
]
},
{
"name": "CTO",
"children": []
}
]
Run Code Online (Sandbox Code Playgroud) 在VB .Net中,可以使用内联If语句,如下所示
if a Then ret = "A" Else ret = "Not A"
Run Code Online (Sandbox Code Playgroud)
我知道也可以嵌套这些语句.我知道这可能不是一个好的做法,因为可读性下降了......
If a Then If b Then ret = "A & B" Else ret = "A & Not B" Else ret = "Not A"
Run Code Online (Sandbox Code Playgroud)
将按如下方式评估:
If a Then
If b Then
ret = "A & B"
Else
ret = "A & Not B"
End If
Else
ret = "Not A"
End If
Run Code Online (Sandbox Code Playgroud)
现在如果我删除最后一个Else语句,我得到这个:
If a Then If b Then ret = "A & …Run Code Online (Sandbox Code Playgroud) 我正在使用javascript,我已经嵌套了jong对象来自mongodb.
"abc": [
{
"a": "01AABCE2207R1Z5",
"b": "Y",
"c": [
{
"ca": "A",
"cb": "AflJufPlFStqKBZ",
"cc": "S008400"
},
{
"cx": "A",
"cy": "AflJufPlFStqKBZ",
"cz": "S008400"
}
]
},
{
"a": "01AABCE2207R1Z5",
"b": "Y",
"c": [
{
"ca": "A",
"cb": "AflJufPlFStqKBZ",
"cc": "S008400"
},
{
"cx": "A",
"cy": "AflJufPlFStqKBZ",
"cz": "S008400"
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
上面的模式有固定的字段,架构中不会有任何变化.
现在我想把它作为平面json数组对象,结果应该是这样的.如果c有多个JSON对象的,应该创建一个新的JSON对象以相同的a,b值
[{
"a": "01AABCE2207R1Z5",
"b": "Y",
"ca": "A",
"cb": "AflJufPlFStqKBZ",
"cc": "S008400"
},
{
"a": "01AABCE2207R1Z5",
"b": "Y",
"cx": …Run Code Online (Sandbox Code Playgroud) 如果你有一个随机矩阵,例如5x5:
A(i,j) = (5 4 3 2 1
4 3 2 1 0
5 4 3 2 1
4 3 2 1 0
5 4 3 2 1)
Run Code Online (Sandbox Code Playgroud)
第二个阵列:
B(1,j) = (4 5 6 7 8)
Run Code Online (Sandbox Code Playgroud)
如果只有当B(1,j)的值大于A的某个colomn值时,才需要将B的值赋值给A?
例如,B(1,1)= 4并且在A的第一个colomn中它大于A(1,1),A(3,1)和A(5,1),所以这些必须被4替换在第二个colomn中,没有什么需要更换,等等.
谢谢!
我有JSON数据,它以字符串形式保存在BigQuery中。
{
"event":{
"action":"prohibitedSoftwareCheckResult",
"clientTime":"2017-07-16T12:55:40.828Z",
"clientTimeZone":"3",
"serverTime":"2017-07-16T12:55:39.000Z",
"processList":{
"1":"outlook.exe",
"2":"notepad.exe"
}
},
"user":{
"id":123456,
}
}
Run Code Online (Sandbox Code Playgroud)
我想要一个结果集,其中每个进程将在不同的行中。就像是:
UserID ProcessName
-------------------------
123456 outlook.exe
123456 notepad.exe
Run Code Online (Sandbox Code Playgroud)
我看到有一个查询重复数据的选项,但据我所知,该字段必须为RECORD类型。
是否可以在子查询中“即时”转换为RECORD类型?(我无法将源字段更改为RECORD)。
还是有其他方法返回期望的结果集?
nested ×10
json ×4
java ×3
loops ×3
if-statement ×2
sql ×2
case ×1
conditional ×1
flatten ×1
for-loop ×1
javascript ×1
logic ×1
matlab ×1
python ×1
r ×1
raspberry-pi ×1
tree ×1
vb.net ×1
view ×1