0% found this document useful (0 votes)
4 views2 pages

Contoh Program Pengolahan String

The document provides examples of string manipulation programs in Java, including string concatenation, sorting, reversing, and extracting characters. Each example is presented in a separate class with relevant code snippets demonstrating the functionality. The programs illustrate basic operations that can be performed on strings using Java programming language.

Uploaded by

Abdul Butun
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Contoh Program Pengolahan String

The document provides examples of string manipulation programs in Java, including string concatenation, sorting, reversing, and extracting characters. Each example is presented in a separate class with relevant code snippets demonstrating the functionality. The programs illustrate basic operations that can be performed on strings using Java programming language.

Uploaded by

Abdul Butun
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Contoh-contoh program olah string

1. Penggabungan string(concatenation)

package olahstring1;
public class OlahString1 {

public static void main(String[] args) {


String namadepan="Ahmad";
String namabelakang="Fauzi";
String nama=namadepan+namabelakang;
[Link]("Halo "+nama+" apa kabar? ");
[Link]([Link](namabelakang)+"anda memang pemuda gentle ");
}

}
2. Pengurutan string
package olahstring2;
public class OlahString2 {

public static void main(String[] args) {


int i,j;
String nama[]={"Agi","Adi","Ari"},tamp;
[Link]("sebelum diurut : ");
[Link]("=================");
for(i=0;i<[Link];i++)
[Link](nama[i]+" ");
[Link]("");
[Link]("\nSetelah diurut : ");
[Link]("==================");
for(i=0;i<([Link]-1);i++){
for(j=(i+1);j<[Link];j++)
if(nama[j].compareTo(nama[i])<1){
tamp=nama[j];
nama[j]=nama[i];
nama[i]=tamp;
}
}
for(i=0;i<[Link];i++)
[Link](nama[i]+" ");
[Link]("");
}

}
3. Membalik urutan
package olahstring3;
import [Link];
public class OlahString3 {

public static void main(String[] args) {


String kata;
[Link]("Ketikkan kalimat sembarang : ");
Scanner input=new Scanner([Link]);
kata=[Link]();
StringBuffer balik;
balik=new StringBuffer(kata);
[Link](kata);
[Link]([Link]());
}

}
4. Mengambil beberapa karakter

package olahstring5;
public class OlahString5 {
public static void main(String[] args) {
int i;
String teks="SOTO BANDUNG",teksmu="";
for(i=1;i<[Link]();i++)
teksmu+=[Link](i);
[Link](teksmu);
}

You might also like