943,695 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 20800
  • Java RSS
Jul 25th, 2004
0

String Class Of Java

Expand Post »
hi everyone,
i am very new in java.can anyone help me to do the following problem:

Write a program to do the following using in-built methods in the string class of java.
1) Find the 5th caracter in the string " RUSTIN BOND"
2) Find the index of character "K" in string "KANSAS".
3) Convert the string "hello world" to uppercase.
4) Replace character 'h' with 'b' in the string"humble".


thank you,
regards,
shantuli
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shantuli is offline Offline
16 posts
since Jul 2004
Jul 25th, 2004
0

Re: String Class Of Java

Greetings.
This would be of help to you.
Java String api
Have a look at java.lang -> String.
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003
Jul 26th, 2004
0

Re: String Class Of Java

String s;
s.charAt(5);

s.indexOf('K');

String t = s.toUpperCase();

s.replace(h,b);
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Jul 27th, 2004
0

Re: String Class Of Java

Ok, the String class is a very important tool in java. Make yourself famaliar with it.
Go to this Weblink to revise some of its properties.
Weblink

Your code should be simliar to this....
------------------------------------------------------------------------
public static void main(String[] args)
{
/*1) Find the 5th caracter in the string " RUSTIN BOND"
2) Find the index of character "K"in string "KANSAS".
3) Convert the string "hello world"to uppercase.
4) Replace character 'h'with 'b'in the string"humble */

String no1 = "RUSTIN BOND";
String no2 = "KANSAS";
String no3 = "hello world";
String no4 = "humble";

//print out the results

//remember java indicies start at 0
System.out.println("\nCurrent String: " + no1);
System.out.println("The 5th character: " + no1.charAt(4));

//remember java indicies start at 0
System.out.println("\nCurrent String: " + no2);
System.out.println("The index of character k: " + (no2.indexOf("K") + 1) );

System.out.println("\nCurrent String: " + no3);
System.out.println("Convert string to uppercase: " + no3.toUpperCase());

System.out.println("\nCurrent String: " + no4);
System.out.println("Replace character h with b: " + no4.replace('h', 'b'));
}
-----------------------------------------------------------------
Hope that helps! Rickste_r
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rickste_r is offline Offline
16 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: SIMPLE BOX GIVING ME PROBLEMS--this is homeowrk but i have tried for hours
Next Thread in Java Forum Timeline: Could U Help Me with dis ?? plz..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC