English French German Spain Italian Dutch Russian Portuguese Japanese Korean Arabic Chinese Simplified

Senin, 29 November 2010

COMPILER Menggunakan Java

Tugas dari salah satu dosen menyuruh untuk membuat compiler dengan menggunakan bahasa pemrograman java.
COMPILER
import java.io.*;
public class Scanner
{
public static void main(String args[]) throws Exception
{
 kataInputStream kata = new kataInputStream(System.in);
 System.out.print("Masukkan Kalimat : ");
     String maskal = kata.readLine();
     char chars[] = maskal.toCharArray();
     char myChars[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',+
            'P','Q','R','S','T','U','V','W','X','Y','Z',+     'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',+
    'r','s','t','u','v','w','x','y','z',' '};     
     int numChars[]=new int[myChars.length];
     for(int x=0;x
 {
        for(int y=0;y
  {
                 if(chars[x]==myChars[y])
   {
                     numChars[y]++;
              }
         }
     }
     for (int x=0;x < myChars.length;x++)
 {
  if(numChars[x] > 0)
  {
          System.out.println(myChars[x] + " = " + numChars[x]);
  }
 }
}
}

Tidak ada komentar:

Posting Komentar