The Artima Developer Community
Sponsored Link

Java Answers Forum
Someone help plz

1 reply on 1 page. Most recent reply: Jul 31, 2003 6:36 AM by David

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
JOhnny

Posts: 1
Nickname: horis
Registered: Jul, 2003

Someone help plz Posted: Jul 30, 2003 2:29 AM
Reply to this message Reply
Advertisement
I'm total n00bie in Java and i cant find the answer to my problem:
I need in public void do this:
s="anotherstring"
dosomething("string")

private String dosomething(String s)
{
String s1 = "";
for(int i = 0; i < s.length(); i++)
s1 = s1 + "" + (char)(s.charAt(i) - 1);
return s1;
}

So, what happens in this function? Can someone explain me? And what does those +"" and (char)??


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: Someone help plz Posted: Jul 31, 2003 6:36 AM
Reply to this message Reply
Sounds to me like you could do with reading some introductory tutorials to Java.

'+' is the concatenation operator which 'joins' strings together.

'(char)' is a cast. It forces whatever is on its right to become a character.

If you ran this program, you'd see what it does. It changes each character in the string, moving it to the previous letter in the alphabet (that's why it is -1).

Flat View: This topic has 1 reply on 1 page
Topic: remove panel and add it again Previous Topic   Next Topic Topic: Execute the applet without java plug-in

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use