| | |
String Class Of Java
![]() |
•
•
Join Date: Jul 2004
Posts: 16
Reputation:
Solved Threads: 0
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
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
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
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
![]() |
Similar Threads
- C++ help (string class) (C++)
- get token from string using string class (C++)
- How to replace repeated substring in other string? (Java)
- error in user defined string class (C++)
Other Threads in the Java Forum
- Previous Thread: SIMPLE BOX GIVING ME PROBLEMS--this is homeowrk but i have tried for hours
- Next Thread: Could U Help Me with dis ?? plz..
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






