我编写了这段代码,意图是每次recurse()调用链都会增加.然而,它(从我用调试器看到的)每次recurse()到达返回值时都会这样做,它会递减值b.如果您想了解我正在尝试做的事情,那么这就是项目征集#14.
http://projecteuler.net/problem=14
private static void euler14()
{
int currentstart=1000000;
int longest = 0;
int current=0;
Integer chain=0;
for(int i = currentstart; i>0; i--)
{
recurse(i,chain);
if(chain > current)
{
current=chain;
longest=i;
}
chain = 0;
}
System.out.print("Euler 14: " + longest + "\n");
}
private static void recurse(int a, Integer b)
{
b++;
if(a==1)
{
return;
}
else if(a%2==0)
{
recurse((a/2), b);
}
else if(a%2==1)
{
recurse(((a*3)+1), b);
}
return;
}
Run Code Online (Sandbox Code Playgroud) 我不完全清楚在调用期望返回与不期望返回的函数时 bash 的 exit 关键字是如何/为什么不一致的。
例如,在以下重现中:
#!/bin/bash
exitfunc()
{
echo "Flag 1"
exit
}
exitfunc
echo "We should never see this."
Run Code Online (Sandbox Code Playgroud)
我们看到输出:
$ ./z.bash
Flag 1
Run Code Online (Sandbox Code Playgroud)
然而,在这个小小的修改中:
#!/bin/bash
exitfunc()
{
echo "Flag 1"
exit
}
foo=exitfunc
echo "We should never see this."
Run Code Online (Sandbox Code Playgroud)
输出显示该函数显然没有退出 shell。
$ ./z.bash
We should never see this.
Run Code Online (Sandbox Code Playgroud)
看来Flag 1第二个版本中的 是存储在 foo 中的值,可能用于存储错误代码。我的问题是,为什么exit在以这种方式调用的函数中会有这种行为?当函数需要返回时,它是否会打开一个新的 shell?如何正确退出这些功能之一?我是否只需要检查捕获器的输出值foo并exit一直包含到调用堆栈中?
谢谢。
我刚刚安装并尝试构建一个简单的Hello world程序,但是我似乎无法找到.exe,也没有任何方式可以看到程序生成"hello world".附件是我要构建的内容的截图,以及我认为它应该输出.exe的文件夹
http://i.imgur.com/HKAmK.png http://i.imgur.com/WK2Hb.png(也不在子文件夹中)
我正在尝试使用以下算法解决Euler#8.问题是,当我修改该行时,我有巨大的评论,错误Unhandled Exception Type IOException出现在我用注释标记的每一行上//###.
private static void euler8()
{
int c =0;
int b;
ArrayList<Integer> bar = new ArrayList<Integer>(0);
File infile = new File("euler8.txt");
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(infile), //###
Charset.forName("UTF-8")));
while((c = reader.read()) != -1) { //###
char character = (char) c;
b = (int)character;
bar.add(b); /*When I add this line*/
}
reader.close(); //###
}
Run Code Online (Sandbox Code Playgroud) 正如标题所说,我创建了一个表,其中一列是varchar(50)类型,但它拒绝INSERT语句,其中第一个值是字符串:
表创建:
CREATE TABLE Fiddy(Lname varchar(50),
-> Height int,
-> Width int,
-> Gas int);
Run Code Online (Sandbox Code Playgroud)
插入尝试
insert into Fiddy VALUES(Smith, 54, 43, 1);
ERROR 1054 (42S22): Unknown column 'Smith' in 'field list'
Run Code Online (Sandbox Code Playgroud)
插入尝试
insert into Fiddy values (4, 5, 5, 6);
Query OK, 1 row affected (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
选择*
select * from Fiddy;
+-------+--------+-------+------+
| Lname | Height | Width | Gas |
+-------+--------+-------+------+
| 4 | 5 | 5 | 6 |
+-------+--------+-------+------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)