This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Jumat, 22 November 2013

KONVERSI BILANGAN DESIMAL KE BINER,



KONVERSI BILANGAN  DESIMAL KE BINER ( SOAL UTS NO 5 ) /STRUKTUR DATA.
 package javaapplication11;
    import java.util.NoSuchElementException;
    import java.util.Scanner;
    /**
    *
    * @author EKO KURNIAWAN
    */
    public class JavaApplication11 {
    private class Element {
    public Object data;
    public Element next;
    public Element( Object data, Element next ) {
    this.data = data;
    this.next = next;
      }
    }
    private Element top;
    public void push( Object data ) {
    if( isEmpty( ) ) {
    top = new Element( data, null );
    } else {
    top = new Element( data, top );
      }
    }
 public Object pop( ) throws NoSuchElementException {
    if( isEmpty( ) ) {
    throw new NoSuchElementException( );
    } else {
    Object data = top.data;
    top = top.next;
    return data;
      }
    }
 public Object peek( ) throws NoSuchElementException {
    if( isEmpty( ) ) {
    throw new NoSuchElementException( );
    } else {
    return top.data;
      }
    }
 public boolean isEmpty( ) {
    return top == null;
    }
 public static void main(String args[]) {
    System.out.println("Program Konversi Bilangan Desimal ke Biner");
    System.out.println("---------------------------------------------------");
    Scanner input = new Scanner(System.in);
    System.out.print("Masukkan Angka -> ");
    int bil = input.nextInt();
    int c = bil;
JavaApplication11 stack = new JavaApplication11();
    if (bil == 0) {
    System.out.println("0");
    }
    while (bil != 0) {
    int a = bil / 2;
    int b = bil % 2;
    stack.push(b);
    bil = a;
    }
System.out.print("Biner dari Angka "+c+" = ");
    while (!stack.isEmpty()) {
    System.out.print(stack.pop());
    }
 System.out.println(" ");
      }
    }

Selasa, 19 November 2013

stack bilangan desimal ke biner



 package javaapplication11;
    import java.util.NoSuchElementException;
    import java.util.Scanner;
    /**
    *
    * @author EKO KURNIAWAN
    */
    public class JavaApplication11 {
    private class Element {
    public Object data;
    public Element next;
    public Element( Object data, Element next ) {
    this.data = data;
    this.next = next;
      }
    }
    private Element top;
    public void push( Object data ) {
    if( isEmpty( ) ) {
    top = new Element( data, null );
    } else {
    top = new Element( data, top );
      }
    }
 public Object pop( ) throws NoSuchElementException {
    if( isEmpty( ) ) {
    throw new NoSuchElementException( );
    } else {
    Object data = top.data;
    top = top.next;
    return data;
      }
    }
 public Object peek( ) throws NoSuchElementException {
    if( isEmpty( ) ) {
    throw new NoSuchElementException( );
    } else {
    return top.data;
      }
    }
 public boolean isEmpty( ) {
    return top == null;
    }
 public static void main(String args[]) {
    System.out.println("Program Konversi Bilangan Desimal ke Biner");
    System.out.println("---------------------------------------------------");
    Scanner input = new Scanner(System.in);
    System.out.print("Masukkan Angka -> ");
    int bil = input.nextInt();
    int c = bil;
JavaApplication11 stack = new JavaApplication11();
    if (bil == 0) {
    System.out.println("0");
    }
    while (bil != 0) {
    int a = bil / 2;
    int b = bil % 2;
    stack.push(b);
    bil = a;
    }
System.out.print("Biner dari Angka "+c+" = ");
    while (!stack.isEmpty()) {
    System.out.print(stack.pop());
    }
 System.out.println(" ");
      }
    }

Senin, 11 November 2013

program java menggunakan stack untuk mengecek kata palindrom



( harap diteliti kembali sebagai bahan belajar dan revisi )
package javaapplication1;   ( ganti namanya sesuai dengan folder project kalian )
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.Scanner;  // From eko kurniawan
/******************************************************************************
* @author eko kurniawan
* @version
*   @2013
******************************************************************************/
public class JavaApplication1                  ( ganti namanya sesuai dengan class project kalian )
{
      public static void main(String[ ] args)
   {
          Scanner stdin = new Scanner(System.in); // Keyboard input      
          String line;                            // One input line
         do
      {
           System.out.print(" MASUKAN KATA: ");
         line = stdin.nextLine( );
           if (is_palindrome(line))
              System.out.println("TERMASUK PALINDROME.");
           else
              System.out.println("TIDAK TERMASUK PALINDROME.");
      }
      while (line.length( ) != 0);
   }
public static boolean is_palindrome(String input)
   {  
      Queue<Character> q = new LinkedList<Character>( );
      Stack<Character> s = new Stack<Character>( );
      Character letter;  
      int mismatches = 0;
      int i;             
      for (i = 0; i < input.length( ); i++)
      {
           letter = input.charAt(i);
         if (Character.isLetter(letter))
         {
            q.add(letter);
            s.push(letter);
         }
      }
     
      while (!q.isEmpty( ))
      {
         if (q.remove( ) != s.pop( ))
            mismatches++;
      }
      return (mismatches == 0);
   }
    }

@Run
 

program java mengecek kata palindrom ( tanpa stack )



package javaapplication7;
import java.util.Scanner;
public class JavaApplication7 {
 public static void main (String[] args) {
   Scanner input = new Scanner(System.in);
String a;
int d=0;
int f=0;
System.out.print("Masukkan kata : ");
        a = input.next();
for (int i = a.length(); i >0 ; i--) {
String c = a.substring(i-1, i);
d=d+1;
String e = a.substring(d-1, d);
if(c.equals(e))
{
f+=1;
}
}
if(f==a.length()){
System.out.println("Kata "+a+" merupakan Palindrome");}
else{
System.out.println("Kata "+a+" bukan Palindrome");}
}
  }