exam questions

Exam 1z0-829 All Questions

View all questions & answers for the 1z0-829 exam

Exam 1z0-829 topic 1 question 25 discussion

Actual exam question from Oracle's 1z0-829
Question #: 25
Topic #: 1
[All 1z0-829 Questions]

Given the code fragment:

Which two statements at Line n1 independently enable you to print 1250? (Choose two.)

  • A. Integer res = 250 + Integer.parseInt(s);
  • B. Integer res = 250 + Integer.valueOf(s);
  • C. Integer res = 250 + s2;
  • D. Integer res = 250;
    res =+ s2;
  • E. Integer res = 250 + s;
  • F. Integer res = 250 + Integer(s2);
Show Suggested Answer Hide Answer
Suggested Answer: CD 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
SrinivasJasti
2 weeks, 2 days ago
Selected Answer: CD
thousand separator in numeric literals is accepted from java7 10_00 means 1000
upvoted 1 times
...
xplorerpj
6 months, 4 weeks ago
CD but there's an error with the display of Answer option D D. Integer res = 250; res =+ s2; This will only return 1000 in result because there's no operator like =+ The correct choice of answer would be as below (for D), D. Integer res = 250; res += s2;
upvoted 1 times
...
james2033
10 months, 4 weeks ago
Selected Answer: CD
package q25; public class Q25 { public static void main(String[] args) { String s = "10_00"; Integer s2 = 10_00; // Line n1 // A. // Integer res = 250 + Integer.parseInt(s); // parseInt exception. // B. // Integer res = 250 + Integer.valueOf(s); // parseInt exception. // C. // Integer res = 250 + s2; // at the end, result = 1250 . // D. Integer res = 250; res += s2; // At then end, result = 1250 . // E. // Integer res = 250 + s; // Syntax error. // F. // Integer res = 250 + Integer(s2); // Syntax error. System.out.println(res); } }
upvoted 2 times
...
supersquax
11 months, 2 weeks ago
Should be C and D, but D should have "+=" instead of "=+". I've tried all the alternatives in an online compiler and these are the only ones that work. A and B would work if "s" were "1000", but parseInt() and valueOf() arent able to handle the underscore in "10_00". E is just plain wrong cuz s is a string and cant be automatically cast to an int. F is wrong cuz "Integer()" casting doesn't exist. One would instead use valueOf() to cast.
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago