Sabtu, 10 April 2010

ProGRAM STRING dalam Java

1. public class StringDemo {
2. public static void main(String[] args) {
3. //Mencari Panjang String
4. String palindrome = "Dot saw I was Tod";
5. int len = palindrome.length();
6. System.out.println ("Panjang String = " + len);
7.
8. //menggabungkan string
9. String str1 = "Belajar";
10. String str2 = " Bahasa";
11. String str3 = " Java";
12. String str4 = str1 + str2 + str3;
13. System.out.println("Hasil str4 = "+ str4);
14. System.out.println("Belajar".concat(" Bahasa").concat(" Java"));
15. }
16.}



Output : Panjang String : 17
Hasil Str4 = Belajar Bahasa Java
Belajar Bahasa Java