说我有以下示例代码:
Scanner scan1 = new Scanner(System.in); // declaring new Scanner called scan1
int x = scan1.nextInt(); // scan for user input and set it to x
System.out.println(x); // print the value of x
scan1.close(); // closes the scanner (I don't know exactly what this does)
Scanner scan2 = new Scanner(System.in); // declaring new Scanner called scan1
int y = scan2.nextInt(); // scan for user input and set it to y
System.out.println(y); // print the value of y
Run Code Online (Sandbox Code Playgroud)
为什么char c = (char)65.8;
Java中允许?
它不应该抛出错误,因为65.8
不是一个确切的Unicode值?我知道在这种情况下,double被截断为整数,65
但是对于我来说,允许程序员进行这样的转换似乎是糟糕的设计.
目前,我的index.html
文件包含
<a href="static/file.ext">Download</a>
Run Code Online (Sandbox Code Playgroud)
我想更改此设置,以便下载URL仅在特定时间内有效.例如,我将如何将其更改为
<a href="get_file?file=file.ext&token=TEMPORARYTOKEN">Download</a>
Run Code Online (Sandbox Code Playgroud)
在我的Flask文件中,我可以拥有
@app.route('/get_file')
def get_file():
filename = request.args.get('file')
token = request.args.get('token')
if token is valid: # what can be done here
return send_from_directory('static', filename)
Run Code Online (Sandbox Code Playgroud)
如何生成和处理令牌?或者我接近这个完全错误?
我有以下代码在Tkinter中创建一个按钮:
button = Button(self.parent_frame, width=100, height=100)
frame = Frame(button)
label = Label(frame, text="This is a button")
frame.pack(fill=BOTH, expand=1)
label.pack(fill=BOTH, expand=1)
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在按钮的某些部分上时,按钮会快速调整到窗口的宽度,然后再回到其初始大小.为什么会这样?Tkinter按钮不允许有孩子吗?
注意:我不打算在按钮内使用框架,我只是在考虑这个假设的目的.因此,我更倾向于解释为什么会发生这种情况,而不是建议解决方法的答案.
我正在尝试安装 Rstudio。我已经下载了这个rstudio-0.98.1103-deb
包。
这是我在执行时遇到的错误:
sudo dpkg -i rstudio-0.98.1103-amd64.deb
Run Code Online (Sandbox Code Playgroud)
我该如何进行安装?任何建议都会很棒。我在 Ubuntu 14.04 上。
background_active
Kivy 具有和属性,分别用于在焦点和未焦点时background_normal
设置小部件的背景。TextInput
但是,这设置了背景图像,而不是rgba
颜色。有一个background_color
属性,但这会设置 的TextInput
背景颜色,无论它是否处于焦点状态。
如何TextInput
根据 是否聚焦来更改 的背景颜色?
假设我有两个内容脚本,codeA.js
并且codeB.js
. 我想知道是否可以在http://www.example.comcodeA.js
上运行并在http://www.domain.com上运行。codeB.js
是否可以将文件content_scripts
中的my 设置manifest.json
为:
"content_scripts": [
{
"matches": ["http://www.example.com", "http:www.domain.com"],
"js": ["codeA.js", "codeB.js"]
}
]
Run Code Online (Sandbox Code Playgroud)
然后让每个脚本检查页面当前位于哪个 URL?如果是这样,我将如何去做这件事?
更新:
我尝试使用以下代码
if(document.location == "http://*.google.com/*" || "https://*.google.com/*") {
alert("you are using google");
} else if(document.location == "http://*.yahoo.com/*" || "https://*.yahoo.com") {
alert("you are using yahoo!");
}
Run Code Online (Sandbox Code Playgroud)
但我不断得到you are using google
。
javascript google-chrome google-chrome-extension content-script
如何从Double对象转换为int?以下代码有效但似乎有些不同寻常(使用两次铸造):
Double d = new Double(4.0);
int i = (int)(double)d;
Run Code Online (Sandbox Code Playgroud)
当我尝试时int i = (int)d
,我从Eclipse(Cannot cast from Double to int
)得到一个错误,这是有道理的.然而,是否有一种更简单的方法将Double对象转换为int?
这样做是不好的做法:
Scanner scan = new Scanner(System.in);
if(scan.nextInt() == 5) { //testing if input is equal to 5
System.out.println("input equals 5");
}
Run Code Online (Sandbox Code Playgroud)
关于什么:
Scanner scan = new Scanner(System.in);
if(scan.nextInt() == scan.nextInt()) { //testing if two inputted ints are equal to each other
System.out.println("input1 equals input 2");
}
Run Code Online (Sandbox Code Playgroud)
我在某处读到这会导致"意外结果",但我不知道这意味着什么.我已经测试了这一点,并没有遇到任何意外的事情.
java conditional if-statement coding-style conditional-statements
据我所知,对变量进行初始化就是为它设置一个值.例如:
String s; // declaring the String (throws an error if you use in conditionals)
String s = null; // declaring and then initializing the String (no error)
Run Code Online (Sandbox Code Playgroud)
但是,当a String
声明时,是不是会自动初始化为null
?因此,编译器不应该抛出错误.
我也注意到String s = new String();
与条件语句一起使用时不会产生任何错误,但String s;
确实如此.我认为这两个陈述基本上是相同的,后者甚至被鼓励超过前者.
我的问题是,为什么String s = new String();
工作但不工作String s;
(使用条件设置它们的价值时)?两个字符串不应该自动初始化null
,因此不会导致错误吗?
加分问题:由于String
对象被自动初始化为null
,为什么以下代码打印为空String
?
String s = new String();
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)
编辑:显然,当我累了,我不会直接思考.整个问题一团糟,我不知道我在想什么.向那些不得不尝试理解它的人道歉.
此外,Oracle文档的默认值:
局部变量略有不同; 编译器永远不会为未初始化的局部变量分配默认值.如果无法初始化声明它的局部变量,请确保在尝试使用它之前为其赋值.访问未初始化的局部变量将导致编译时错误.
这回答了上面的问题.
java ×5
python ×3
casting ×2
double ×2
button ×1
char ×1
coding-style ×1
conditional ×1
download ×1
flask ×1
if-statement ×1
int ×1
javascript ×1
kivy ×1
object ×1
python-2.7 ×1
r ×1
rstudio ×1
string ×1
textinput ×1
tkinter ×1