我应该为第二类斯特林数写一个函数,由下式给出:
为此,我在R中编写了以下函数:
stirling <- function(n, k)
{
sum = 0
for (i in 0:k)
{
sum = sum + (-1)^(k - i) * choose(k, i) * i^n
}
sum = sum / factorial(k)
return(sum)
}
Run Code Online (Sandbox Code Playgroud)
问题的下一部分是"为n = 20创建一个图,k = 1,2,...,10".我做了一些研究,我认为这些方法curve
或者plot
可能对我有帮助.但是,我猜这些方法是y
在形式f(x)
(即单个参数)时使用.但是在这里,我的函数中有两个参数(n
和k
),stirling
所以我不知道如何处理它.
此外,我尝试将k
(0,1,2 ...,10)的值转换为矢量,然后将它们传递给stirling
,但stirling
不接受矢量作为输入.我不知道如何修改代码来生成stirling
接受向量.
有什么建议?
在Python 3中,我编写了一个简单的命令来接受来自用户的整数输入:
x = int(input("Enter a number: "))
Run Code Online (Sandbox Code Playgroud)
如果我跳过该int()
部分并简单地使用x = input("Enter a number: ")
,我的输入数据类型是一个字符串,而不是整数.我明白那个.
但是,如果我使用以下命令:
x = eval(input("Enter a number: "))
Run Code Online (Sandbox Code Playgroud)
输入的数据类型是'int'.
为什么会这样?
我最近了解到关闭 Spring Boot 应用程序的正确方法是:
public class Application {
@Bean
public ExitCodeGenerator exitCodeGenerator() {
return new ExitCodeGenerator() {
@Override
public int getExitCode() {
return 0;
}
};
}
public static void main(String[] args) throws Exception {
System.exit(SpringApplication.exit(SpringApplication.run(Application.class, args)));
}
}
Run Code Online (Sandbox Code Playgroud)
这应该返回退出代码 0,或者我将其配置为在getExitCode()
方法中返回的任何内容。我的问题是 - 执行上述方法与执行以下方法有什么区别:
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
System.exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
两种方法似乎都以完全相同的方式关闭应用程序,至少在控制台中是这样。那么有什么区别呢?
当我尝试git branch
命令查看我的分支列表时,我看不到任何东西.快照:
正如你所看到的,命令git branch
和git branch -v
不显示新的分支,因为他们应该.
Details
:我一直在搞乱我的存储库一段时间了.我的repo的github网页说该分支hw3
是提前17次提交.
是因为我删除hw
了当地仓库中分支机构的所有内容吗?
此外,当我尝试该命令时git checkout master
,我收到以下消息:
error: pathspec 'master' did not match any file(s) known to git
Run Code Online (Sandbox Code Playgroud)
截至目前,我删除hw
了我机器上的分支中的所有内容,但Github网页仍显示所有这些文件.
另外,我在命令输入git init
,而在hw3
分支从计算器上的另一个问题的建议.这对我有什么影响?
最初,我的hw3
分支中有一堆文件,而我的主分支中只有一个README文件.我只想让事情恢复正常.
我该怎么办?谢谢!
例如,我正在迭代字典mydict
,如下所示:
mydict = {"Name" : "Vincent Vega",
"Profession" : "Gangster",
"Age" : "42"}
for k in mydict:
print k, mydict[k]
Run Code Online (Sandbox Code Playgroud)
现在,k
它只是一个我甚至没有声明的循环变量.编译器如何知道k
,我的意思是字典的键?
我在 IntelliJ 中有一个 Spring Boot 应用程序,最初配置为正常启动,如下所示:
public static void main(String[] args) throws Exception {
SpringApplication.run(AccountApiApplication.class, args).close();
}
Run Code Online (Sandbox Code Playgroud)
我在方法中添加了一个 try-catch 块main
来处理启动期间发生的任何错误(例如缺少配置文件等),现在看起来像:
public static void main(String[] args) throws Exception {
try {
SpringApplication.run(AccountApiApplication.class, args).close();
}
catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
Run Code Online (Sandbox Code Playgroud)
添加此后,我的应用程序总是以退出代码 1 退出。即使没有错误也是如此。我尝试打印发生的异常,它是这样的:
org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException
at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread(SilentExitExceptionHandler.java:90)
at org.springframework.boot.devtools.restart.Restarter.immediateRestart(Restarter.java:184)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:163)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:552)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:67)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at edu.iu.es.ebs.AccountApiApplication.main(AccountApiApplication.java:90)
Process finished with exit …
Run Code Online (Sandbox Code Playgroud) 我正在使用 ajava.sql.Date
将日期字段存储在我的域对象之一中。该字段映射到 MySQLDATE
列。当我尝试通过 Jackson 将此字段序列化为 JSON 时,Jackson 似乎没有考虑夏令时。
这是我的域对象中的字段的样子:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "EST")
private Date date;
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,Jackson 已被指示将时区解释为 EST。我的 MySQL 数据库也使用 EST 时区:
SHOW VARIABLES LIKE '%zone';
Output:
system_time_zone | EST
time_zone | SYSTEM
Run Code Online (Sandbox Code Playgroud)
我的问题是,对于夏令时开始和结束之间的日期,杰克逊返回的日期比数据库中存储的日期少一天。我假设这是因为杰克逊没有考虑夏令时。
我通过尝试在 Java 字段中将日期格式从 更改为yyyy-MM-dd
来得出此结论。yyyy-MM-dd HH:mm:ss
我注意到服务器返回了类似 的内容2017-03-13 00:00:00
,但杰克逊将其序列化为2017-03-12 23:00:00
(少一小时,这是 EST 时间受夏令时影响的时间)。
有什么办法可以克服这个问题吗?另外,java.sql.Date
考虑到它没有时间对应项,使用的类型是否正确?我一直在考虑使用它java.time.LocalDate
,但我还没有看到它是否会成功。
提前致谢!
所以我从我的主管那里得到了一个代码,我在理解方面遇到了问题。我希望使用create_rectangle
我提供参数/坐标的方法在光标所在的位置绘制一个矩形:
rect = create_rectangle(x, y, x + 10, y + 10, fill = 'blue', width = 0)
我想x
和y
这里是我的光标的当前坐标相对于我的根窗口。
在将它们传递给这个函数之前,在我的代码中计算x
和y
计算的方式是:
x = root.winfo_pointerx() - root.winfo_rootx()
y = root.winfo_pointery() - root.winfo_rooty()
Run Code Online (Sandbox Code Playgroud)
我一生都无法理解为什么要这样做。我试着做
x = root.winfo_pointerx()
y = root.winfo_pointery()
Run Code Online (Sandbox Code Playgroud)
而且也只是
x = root.winfo_rootx()
y = root.winfo_rooty()
Run Code Online (Sandbox Code Playgroud)
但这些都没有绘制光标所在的矩形。我也尝试查看文档,但无法真正理解发生了什么。
那么,为什么x = root.winfo_pointerx() - root.winfo_rootx()
和y = root.winfo_pointery() - root.winfo_rooty()
正在这里做什么?
假设我有一个Animal类,我想为每种动物设置不同的类和功能.有两种方法可以做到这一点:
方法覆盖继承:
public class Animal {
public void sound() {}
}
public class Dog extends Animal {
public void sound() {
System.out.println("bark");
}
}
public static void main(String[] args) {
Animal dog = new Dog();
dog.sound();
}
Run Code Online (Sandbox Code Playgroud)通过扩展Animal
抽象类:
abstract public class Animal {
abstract public void sound();
}
public class Dog extends Animal {
public void sound() {
System.out.println("bark");
}
}
public static void main(String[] args) {
Dog dog = new Dog();
dog.sound();
}
Run Code Online (Sandbox Code Playgroud)那么为什么我们一直使用抽象类,当第一种方法完成同样的事情时呢?我理解为什么我们使用接口 - 它建立了一个契约,任何实现它的类都必须具有某些方法和属性.但是,当通过简单的继承实现同样的事情时,抽象类的用途是什么?
我正在编写KSH Shell脚本。它从JSON文件中读取,该文件包含控制字符(如)\n
,\r
并\t
代替实际的换行符或制表符(因此,控制字符被作为实际的字符串读取)。我正在使用jq
此JSON文件解析所需的内容,并将其附加到文本文件中。该文本文件还最终具有字符串,如\n
,\t
而不是换行符,制表符等。我希望文本文件具有这些控制字符的实际含义。
例如,对于字符串"I\nam\na\ngood\nboy"
,我希望我的文件具有:
I
am
a
good
boy
Run Code Online (Sandbox Code Playgroud)
关于如何在Shell脚本中完成此操作的任何想法?
注意:我用KSH写作,但是以bash等答案是可以接受的。