Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File IO

 
nikhil nandu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given method which extracts and returns file extension from the
given file name:
static String getName(String s) {
int n = s.indexOf('.');
return s.substring(n); }
Which of the following statements are true?
A. This method always returns a wrong extension
B. This method may return a wrong extension under certain
circumstances
C. This method may throw unchecked exception
D. This method works fine
Please help.
Thanks.
 
Bin Wu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikhil,
I think the ans should be 'a'.
Because the code return the extension name and '.', so right code should be:
return s.substring( n+1 );
hope to help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic