Sudhir Kumar Ojha wrote:The following question is asked in my interview
Suppose that i have a string name
String str="Sudhir Kumar Ojha";
Now i want to print only SKO w ithout using methods
Sudhir Kumar Ojha wrote:
mainly charAt(int index); method
Sudhir Kumar Ojha wrote:Yes Exactly
mainly charAt(int index); method
Sudhir Kumar Ojha wrote:Can you write a code
Not even a signle method? like we can do that in C language using only loop?Sudhir Kumar Ojha wrote:Now i want to print only SKO w ithout using methods
M Khalid wrote:without using String methods?
Sudhir Kumar Ojha wrote:Yes Exactly
mainly charAt(int index); method
Don't you think, you still used .split() and .substring() methods of String, what do you say?M Khalid wrote:
Ganesh Patekar wrote:Don't you think, you still used .split() and .substring() methods of String, what do you say?
Ok, you mean to say we are allowed to use charAt() method ?Henry Wong wrote:which only allowed the charAt() method.
Ganesh Patekar wrote:
Ok, you mean to say we are allowed to use charAt() method ?Henry Wong wrote:which only allowed the charAt() method.
Sudhir Kumar Ojha wrote:
Yes Exactly
mainly charAt(int index); method
Ganesh Patekar wrote:
Interviewer might intentionally ask you not even using single method of String Or StringBufffer Or StringBuilder and try to confuse you and make you use logic like we do in C where String is an array of chars which is not in case of Java.
If allows few methods then, this is what so far I tried, there could be more ways to do so.. Output:
Using charAt method only
SKO
Using getChars() and length() methods
SKO
Using split(\s) method only
SKO
M Khalid wrote:Exactly , interviewer needs alternative methods.
Consider Paul's rocket mass heater. |