literals

Literal Assignment in Java [duplicate]

落爺英雄遲暮 提交于 2020-01-03 12:25:28
问题 This question already has answers here : Java's L number (long) specification (6 answers) Closed 3 years ago . what's the difference in defining double example = 23.1d or double example = 23.1 Why long, float and double can end with l, f, d? 回答1: There is no difference between double example = 23.1d; and double example = 23.1; because a floating point literal without a type suffix is always interpreted as a double. The type suffixes are necessary in order to avoid ambiguities in certain

Literal Assignment in Java [duplicate]

旧时模样 提交于 2020-01-03 12:23:41
问题 This question already has answers here : Java's L number (long) specification (6 answers) Closed 3 years ago . what's the difference in defining double example = 23.1d or double example = 23.1 Why long, float and double can end with l, f, d? 回答1: There is no difference between double example = 23.1d; and double example = 23.1; because a floating point literal without a type suffix is always interpreted as a double. The type suffixes are necessary in order to avoid ambiguities in certain

SyntaxError: identifier starts immediately after numeric literal. Passing php variable to JavaScript

霸气de小男生 提交于 2020-01-02 18:04:13
问题 I am trying to pass in two variables to a JavaScript function: the input itself and the user id. I call the function using the onclick attribute of the input. echo "<input type = 'submit' class = 'replyButton' id = 'replyButton' value = 'reply' onclick = 'insertComment(this, $user_id);'>"; The variables go into a JavaScript function: function insertComment(input, user) { //use input and user id to carry out tasks. } The error message given is at the function call to 'insertComment()' in the

Unexpected int/Integer behavior when number starts by 0

别说谁变了你拦得住时间么 提交于 2020-01-02 14:31:50
问题 I can't understand why this is not printing the expected value (400300) when I put extra zeros in front of the number: System.out.println(new Integer(0400300)); // prints 131264 System.out.println(0400300); // prints 131264 If I put one or more zeros in front of the number, the expected value is not printed. // JUnit test does not pass: assertTrue(0400300 == 400300); // returns false!? 回答1: Adding 0 to the front made the number an Octal literal . So: 0400300 = 3 * 8 ^ 2 + 4 * 8 ^ 5 = 131264

Unexpected int/Integer behavior when number starts by 0

无人久伴 提交于 2020-01-02 14:31:49
问题 I can't understand why this is not printing the expected value (400300) when I put extra zeros in front of the number: System.out.println(new Integer(0400300)); // prints 131264 System.out.println(0400300); // prints 131264 If I put one or more zeros in front of the number, the expected value is not printed. // JUnit test does not pass: assertTrue(0400300 == 400300); // returns false!? 回答1: Adding 0 to the front made the number an Octal literal . So: 0400300 = 3 * 8 ^ 2 + 4 * 8 ^ 5 = 131264

Underscores in literals are not supported at this language level

纵然是瞬间 提交于 2020-01-02 05:14:29
问题 I got this error when creating a final double using underscores to make the double more readable. It was declared in a run() method. public void run() { final double nanoSeconds = 1_000_000_000.0 / 60.0; } I'm using IntelliJ IDEA 12. 回答1: In IntelliJ IDEA you have to change Project language level in project settings to 7.0 level: 回答2: Yes..you need to change the default language level settings if you are using and IDE. For IntelliJ users it is under File --> Project Structure --> Projects.

clearTimeout() not working

ぃ、小莉子 提交于 2020-01-02 04:06:10
问题 In the following code the clearTimeout() function doesn't seem to clear the timer. Please note: I've stripped the code down a bit to show the relevent parts. Any ideas? var Gallery = { next: function() { // does stuff }, close: function() { Gallery.slideshow("off"); }, slideshow: function(sw) { if (sw == "off") {clearTimeout(timer);} var timer = setTimeout(function() {Gallery.next();Gallery.slideshow();}, 1000); }, }; FULL CODE: <!doctype html> <html> <head> <meta charset="utf-8"> <title

clearTimeout() not working

谁说胖子不能爱 提交于 2020-01-02 04:06:06
问题 In the following code the clearTimeout() function doesn't seem to clear the timer. Please note: I've stripped the code down a bit to show the relevent parts. Any ideas? var Gallery = { next: function() { // does stuff }, close: function() { Gallery.slideshow("off"); }, slideshow: function(sw) { if (sw == "off") {clearTimeout(timer);} var timer = setTimeout(function() {Gallery.next();Gallery.slideshow();}, 1000); }, }; FULL CODE: <!doctype html> <html> <head> <meta charset="utf-8"> <title

How can I use a dynamic format string with the format! macro?

陌路散爱 提交于 2020-01-02 00:57:18
问题 I just started learning Rust, and I'm making some small tools to help me understand the language. I have a problem formatting a String using the format! macro. As format! takes a literal, I am not able pass my string to it. I want to do this to dynamically add strings into the current string for use in a view engine. I'm open for suggestions if there might be a better way to do it. let test = String::from("Test: {}"); let test2 = String::from("Not working!"); println!(test, test2); What I

c++ passing a string literal instead of a const std::string&?

*爱你&永不变心* 提交于 2020-01-01 05:08:13
问题 I have the following code which compiles with no warnings (-Wall -pedantic) with g++ #include <iostream> #include <string> using namespace std; class Foo { public: Foo(const std::string& s) : str(s) { } void print() { cout << str << endl; } private: const std::string& str; }; class Bar { public: void stuff() { Foo o("werd"); o.print(); } }; int main(int argc, char **argv) { Bar b; b.stuff(); return 0; } But when I run it, only the newline is printed out. What is going on? If I were to do this