class pertama
package stack.polindrom;
import java.util.Scanner;
/**
*
* @author fieta
*/
public class StackPolindrom {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
baru loe = new baru (15);
String pieta;
System.out.println("Tugas Struktur Data(NIM : 294, 304, 290)");
System.out.print("Masukkan Kata yang akan dibalik: ");
pieta = input.nextLine();
for(int st=0; st<pieta.length();st++)
loe.push(new Character(pieta.charAt(st)));
loe.view();
char c[] = pieta.toCharArray();
String emp = "";
for(int s=c.length-1;s>=0;s--){
emp = emp + c[s];
}
if (emp.equals(pieta)){
System.out.println("kalimat/kata polindrom");}
else{
System.out.println("bukan kalimat/kata polindrom");}
}
}
import java.util.Scanner;
/**
*
* @author fieta
*/
public class StackPolindrom {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
baru loe = new baru (15);
String pieta;
System.out.println("Tugas Struktur Data(NIM : 294, 304, 290)");
System.out.print("Masukkan Kata yang akan dibalik: ");
pieta = input.nextLine();
for(int st=0; st<pieta.length();st++)
loe.push(new Character(pieta.charAt(st)));
loe.view();
char c[] = pieta.toCharArray();
String emp = "";
for(int s=c.length-1;s>=0;s--){
emp = emp + c[s];
}
if (emp.equals(pieta)){
System.out.println("kalimat/kata polindrom");}
else{
System.out.println("bukan kalimat/kata polindrom");}
}
}
class ke dua
package stack.polindrom;
public class baru {
private char[]may;
private int top;
public baru (int cap){
may=new char[cap];
top=-1;
}
public void push(char element){
may[++top]=element;
}
public char pop(){
return may[top--];
}
public boolean isEmpty(){
return top<0;
}
public void view(){
System.out.println();
System.out.print("Hasilnya adalah : ");
while(!isEmpty()){
char nilai = pop();
System.out.print(nilai);
}
System.out.println(" ");
}
}
public class baru {
private char[]may;
private int top;
public baru (int cap){
may=new char[cap];
top=-1;
}
public void push(char element){
may[++top]=element;
}
public char pop(){
return may[top--];
}
public boolean isEmpty(){
return top<0;
}
public void view(){
System.out.println();
System.out.print("Hasilnya adalah : ");
while(!isEmpty()){
char nilai = pop();
System.out.print(nilai);
}
System.out.println(" ");
}
}
nih hasil dari run program gan!
No comments:
Post a Comment