• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Question - Im in Doubt

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was studing about String and i cant understand why some characters have changed to Uppercase and other to LowCase.


Here the code :
----------------------------------------------------------------------------
public class StringsDemo {
public static void main(String[] args) {
String palindrome = "Dot saw I was Tod";
int len = palindrome.length();
StringBuilder dest = new StringBuilder(len);
for (int i = (len - 1); i >= 0; i--) {
dest.append(palindrome.charAt(i));
}
System.out.println(dest.toString());
}
}
----------------------------------------------------------------------------
The output from this program is:

doT saw I was toD
----------------------------------------------------------------------------

WHY NOT "Dot saw I was Tod" ?

Thanks,
Fred.
[ June 15, 2005: Message edited by: Frederico Werly ]
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at what you are doing. Your program does not change the case of any of the characters, it simply reverses the order.
 
Frederico Werly
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH my god !!! is true !!!

Thanks .. eheheheh .. LOL !!
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steven Bell:
Look at what you are doing. Your program does not change the case of any of the characters, it simply reverses the order.



good catch up steven...
keep it up..

Thanks
Karthik_Techie
SCJP1.4,ICAD 285,Prep SCJA.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are these type of questions being asked in Sun exams?
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Arulkumar Gopalan:
Are these type of questions being asked in Sun exams?



Yes, to get a feel for what are the questions that may be asked in exam take a look at some mock exams in each topic. As an example, lets look at http://www.examulator.com/phezam/question.php Question No=36 ( The question changes daily, so you may not get the same question when u visit. I am mentioning the original URL as part of JavaRanch question posting policy ).

Question : What will happen when you attempt to compile and run the following code?



  • 1 Compile time error, StringBuilder cannot be cast to a String.
  • 2 Compilation but runtime exception where the code attempts to cast StringBuilder to String.
  • 3 Compilation and output of "JohnSmith" at runtime.
  • 4 Compilation but blank output at runtime.


  • The Correct Answer is
    1) Compile time error, StringBuilder cannot be cast to a String.

    When I read thru the program, the first thing that stuck me was that main( String[] ) method calls constructor, but constructor does not call output( StringBuffer ) method. There is a possibility that I might not focus on the compilation error.

    In code related questions, there may be code which distracts the candidate from the real answer. There would be no questions that deliberately confuse you, like for example declaring a variable called "l1" ( the lowercase L char follwed by number 1 = one ) and some other place use a variable "ll" ( two lowercase L chars in sequence ) and ask if the code will compile.

    But you might expect a question which tests a concept like a main method signature like main( String args ) - Note that though the variable is called args, but its not a String array. A class with this main method will compile fine, but not run because jvm will try to find the main( String[] ).

    <Bottomline>Look thru some mock exams</Bottomline>

    Visit The JavaRanch mock exam @ http://www.javaranch.com/roundup.jsp[/URL]
     
    Mahesh Kumaraguru
    Ranch Hand
    Posts: 109
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The confusing variable names depends on font - for example lowercase L and number 1 look clearly distinct above, but "rn" lowercase RN and "m" lowercase M may look more similar.
     
    Arulkumar Gopalan
    Ranch Hand
    Posts: 104
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    From what I understand, these kinds of questions are like reviewing the written code. So, it is more like testing ´┐ŻReview Effectiveness´┐Ż of a person in the exam. A person might have good technical knowledge, might not be a good reviewer. Whatz your thought? :roll:
     
    Mahesh Kumaraguru
    Ranch Hand
    Posts: 109
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Arulkumar,

    Review effectiveness questions like clear naming of variables are not part of exam, but a question asking will a class with method "public static void main( String args )" compile ? run ? is testing the java programming language basics. There will be no attempt to confuse the candidate, but the candidate is expected to be clear of language fundamentals.
     
    We don't have time for this. We've gotta save the moon! Or check this out:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic