IDEONE Java Basics 105 – String and Character
PREREQUISITE
This tutorial uses the online compiler IDEone (www.ideone.com ).
IDEone gives you few benefits:
1) Zero setup. You just need Internet Connection and a modern Web Browser.
2) Online storage. You can refer back to the codes at later time.
3) Public codes available. You can also see how others write codes and learn from them as well.
4) Online Learning. You can ask a companion at remote location to help edit the codes or review your codes for improvements or troubleshooting algorithms.
STEPS
1) Start with the basic template
Browse http://ideone.com/RpasKS
Clone the code above. (Click the Fork button).
2) Edit the codes.
2-1) Add:
a) String variable declaration statement.
b) String variable assignment statement.
c) Output statement.
String first_name;
first_name = "William";
System.out.println(first_name);
|
2-2) Run.
2-3) Add:
a) A Character variable declaration and init statement, and
b) A String variable declaration and init statement.
After line no.13
char wordSeparator=',';
String family_name = "H";
|
2-4) Edit:
Include the new variables into the Output Statement.
System.out.println(first_name+wordSeparator+family_name);
|
2-5) Run.
3) String/Character Value Conversion And Output
3-1) Add the following variable declaration statements and output statement after line no.16.
char char_letter=first_name.charAt(0);
String string_letter=Character.toString(char_letter);
System.out.println(char_letter);
System.out.println(string_letter);
|
3-2) Run.
3-3) Add the following output statement at the end of the above codes.
System.out.println(char_letter+wordSeparator+string_letter);
|
3-4) Run. What is the outcome?
3-5) Add another output statement at the end of the above codes.
System.out.println(""+char_letter+wordSeparator+string_letter);
|
3-6) Run. What is the outcome?
No comments:
Post a Comment