Discussion :: Strings - General Questions (Q.No.13)
Vaishnavi.K said: (Jul 29, 2011) | |
Compare the ASCII value of I and i. |
Mandar said: (Aug 30, 2011) | |
How can possible that answer please send me reply. |
Abhitesh Tyagi said: (Sep 20, 2011) | |
As we know that compareTo() compares the current instance with another instance // int n=string.compareTo(s1,s2); the compare method performs a case sensitive comparison and returns different integer values for different conditionsas under: . 0 ,if s1 = s2 . 1 ,if s1>s2 . -1 ,if s1<s2 For example if s1="abc" and s2="ABC" Then n will be assigned a value of -1.because a lowercase letter has a smaller ASCII value than an uppercase letter. |
Kanika Kapoor said: (Nov 1, 2011) | |
If the first string is bigger, the result is 1. If both strings are equal, the result is 0. If the first string is smaller, the result is -1. |
Rajkumar said: (Dec 27, 2011) | |
No we know that ascii value of A TO Z is 65 to 90 and Ascii value of a To z is 97 to 122 ascii value of I is < i 73<105 so result is 1 |
Uttam Jaiswal said: (Jan 26, 2012) | |
Correct answer is -1 because CompareTo sorts data in ascending order and string s2 comes first with higher value. |
Anurag said: (Nov 19, 2012) | |
compareTo method in string class used to compare two strings if both were matching it will return one otherwise will return -1. |
Arun Gupta said: (Apr 8, 2015) | |
Answer is -1 because CompareTo sorts data in ascending order and string s2 comes first with higher value. 0, if s1=s2. 1, if s1>s2. -1, if s1<s2. |
Sudarshan said: (Jul 4, 2015) | |
As we know that compareTo() compares the current instance with another instance. int c; c = s1.CompareTo(s2); s1<s2 then -1. s1>s2 then 1. s1 == s2 then 0. |
Soniya said: (Aug 24, 2015) | |
I have one doubt, suppose it is comparing ASCII value of both string. Then s1 will have greater ASCII value then s2. So answer will, s1>s2 then 1. Please give me solution. |
Arvind said: (Oct 19, 2015) | |
I think same @Soniya and my question is same to you? Please any one give answer. |
Post your comments here:
Name *:
Email : (optional)
» Your comments will be displayed only after manual approval.