Powered By Blogger

Minggu, 09 Januari 2011

Contoh Sederhana Progran JAVA


TUGAS PRAKTIKUM JAVA I

I.            TUGAS PROGRAM 1

Listing program  :

package modul7tugas1;
import javax.swing.*;
public class Main {

   
    public static void main(String[] args) { System.out.println("============================================");
System.out.println("=                  Program Mengurutkan Bilangan Acak                    =");
      System.out.println("============================================");
      System.out.println();

        String kali= JOptionPane.showInputDialog("Ingin Berapa Bilangan : " );
        int x =Integer.parseInt(kali);

        int[] nilai=new int[x];
       
        int i,j;
        int a;
        System.out.println("Bilangan Sebelum di Urutkan (ACAK) : ");
        for(i=0;i<x;i++)
        {
        String bilangan= JOptionPane.showInputDialog("Masukkan Bilangan : " );
        nilai[i]=Integer.parseInt(bilangan);
        System.out.print(" "+bilangan);
        }
System.out.println("\n");

for (i=0;i<x;i++)

    for(j=0;j<x;j++)
        if(nilai[i]<nilai[j])
        {
            a=nilai[i];
            nilai[i]=nilai[j];
            nilai[j]= a;
        }



System.out.println("Bilangan Setelah di Urutkan :");

 for (i=0;i<x;i++)
       {
           System.out.print(" " +nilai[i]);
       }
System.out.println("\n");


for(i=0;i<1;i++)
        {
             System.out.println(" Bilangan terkecil adalah : " + (nilai[i]));
        }
       
        for(i=0;i<x;i++)
             for(j=0;j<x;j++)
             {
            if(nilai[i]>nilai[j])
            {
               nilai[j]=nilai[i];
            }
             }
        for(i=0;i<1;i++)
        {
             System.out.println("\n Bilangan Tebesar adalah : " + (nilai[i]));
        }

      System.out.println();
      System.out.println("===========================================\n");
    }

}

Silahkan Download contoh program java lainnya   beserta Tampilan  outpunya di sini :
  1. http://www.4shared.com/document/YzO11ExM/AGUSZ_Cth_Program_JAVA.html
  2. http://www.4shared.com/document/DdSTPFvZ/AGUSZ__Laporan_Java__.html

Tidak ada komentar:

Posting Komentar