Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion Of string

 
Subhash Pavuskar
Ranch Hand
Posts: 57
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one give me the Code to Convert String Upper case to lower case and vice versa Without using Function.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that is going to be very hard, because there is no way to get at the characters inside a string without calling any method of the String class.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most here will not write the code and give it to you. It's a bit insulting that you'd ask.

However, if you try to write the code and need help along the way, many here are waiting for you to ask and would be honored to provide assistance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote:Most here will not write the code and give it to you. It's a bit insulting that you'd ask.

I don't think it is insulting to ask, but here at JavaRanch we want to help people learn Java. People don't learn Java by having their homework questions answered by others. So, we don't provide answers to homework questions; instead we encourage people to first try something themselves, and if someone doesn't know how to proceed, we're happy to show and explain the right direction.
 
Subhash Pavuskar
Ranch Hand
Posts: 57
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is asked me in interview and i dint get idea how to code for that so i asked ... but my intention was not insulting or hearting any one .
 
Subhash Pavuskar
Ranch Hand
Posts: 57
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your support Mr. Jesper de Jong ..
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subhash Pavuskar wrote:This question is asked me in interview and i dint get idea how to code for that so i asked ... but my intention was not insulting or hearting any one .

No harm done - by you, anyway.
Giving the background you just gave would have been helpful in answering your question.
Function is not a word used in Java that has a common meaning to all. Do you know what the interview question meant by the word "function."
 
Subhash Pavuskar
Ranch Hand
Posts: 57
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant i cant use the function toUpperCase and toLowerCase .
 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe there is a constant number found inbetween the lowercase letters and uppercase ones, while watching the ascii table ?
Let's say the distance between 'a' and 'A' is 32. Hint: What would it be between 'b' and 'B' ?

Cheers
Claudiu
 
Subhash Pavuskar
Ranch Hand
Posts: 57
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ya you are right we can solve this using ascii value good work Claudiu..
thanks.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of those questions where there is no real answer. If it was posed by an interviewer, they wanted to see how you'd think about the problem. If they are a bad interviewer, they have some trick or hack in mind, and unless you come up with THEIR hack, they mark you down.

I would ask the interviewer "Why can't I use the methods?"

if they insist, my first thought would be to construct a StringBuffer from the String, and use its methods.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also methods in the Character class which allow you to work out whether a char is upper-case or lower-case. The trick about adding 32 (actually it would look better if you said 0x20, then you can catch out the interviewer) might only work for ASCII characters.
 
Paul Clapham
Sheriff
Pie
Posts: 20717
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claudiu Chelemen wrote:Maybe there is a constant number found inbetween the lowercase letters and uppercase ones, while watching the ascii table ?
Let's say the distance between 'a' and 'A' is 32. Hint: What would it be between 'b' and 'B' ?


Or maybe there isn't such a constant... the distance between 'ă' and 'Ă' is not 32, but -1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic