Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialoussama zeglama
Courses Plus Student 340 PointsI don't know when to put the " " ? For example int age = Integer.parseInt("30"); int age = Integer.parseInt(AGE);
NEED HELP ?
2 Answers
Steven Parker
231,269 PointsIt looks like you have it correct in your examples.
Quotes go around a literal string (like "30") but never around a variable name (AGE).
Mike Meany
3,988 PointsTo reiterate what Steven said, a String will always have quotes around it, variables wont. To expand a bit; ints will always be numbers but never have quotes, strings can be/contain letters, symbols or numbers and will always have quotes. Lets take the example of;
int x = 1; int y = 2; System.out.println(x + y);
This will output 3 as it adds the two numbers together
now take this example
String x = "1"; String y = "2";
System.out.println(x + y);
This will output 12 as it concatenates the two strings together
If you wanted to add the two numbers together from example 2 then you would have to parse them and it would look something like this;
System.out.println(Integer.parseInt(x) + Integer.parseInt(y));
or
System.out.println(Integer.parseInt("1") + Integer.parseInt("2"));
oussama zeglama
Courses Plus Student 340 Pointsoussama zeglama
Courses Plus Student 340 Pointsyou mean by literal string just numbers ?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsA literal string can have anything ("Bob", "robots", "this is a test", etc.). But one that you might give to "parseInt" would just have numbers.
oussama zeglama
Courses Plus Student 340 Pointsoussama zeglama
Courses Plus Student 340 PointsSo what s the difference between the variable name and the literal string ?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThe variable name represents the value that was previously assigned to it.
A literal string only represents what is contained in the quotes.