Fat’s Albojongi

Just another WordPress.com weblog

serba serbi latihan java di kampus

Posted by fatoni95 pada Februari 1, 2009

<!– /* Font Definitions */ @font-face {font-family:”Traditional Arabic”; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:178; mso-generic-font-family:auto; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:8193 0 0 0 64 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:””; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; mso-bidi-font-size:20.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”; mso-bidi-font-family:”Traditional Arabic”;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; mso-bidi-font-size:20.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”; mso-bidi-font-family:”Traditional Arabic”;} span.MsoPageNumber {font-family:”Times New Roman”; mso-bidi-font-family:”Times New Roman”;} @page Section1 {size:612.1pt 936.1pt; margin:56.7pt 56.7pt 155.95pt 56.7pt; mso-header-margin:.5in; mso-footer-margin:127.6pt; mso-page-numbers:1; mso-paper-source:0;} div.Section1 {page:Section1;} –>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:””;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:”Times New Roman”;
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}

SERBA SERBI CONTOH SOURCE CODE JAVA

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.*;

import java.lang.*;

import javax.swing.*;

import java.lang.String;

public class komen

{

public static void main (String args[]) throws IOException

{

BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );

char k;

String komen = ” “;

System.out.print(“Masukkan karakter = “);

k = (char) dataIn.read();

if (k == ‘d’)

{

//System.out.println(“Anda berhasil”);

komen = “anda berhasil”;

}

else

{

//System.out.println(“Anda belum berhasil”);

komen = “anda belum berhasil”;

}

System.out.println(komen);

}

}

import java.io.*;

public class nilai

{

public static void main(String[]arg)throws IOException

{

BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));

char lagi=’y’;

do

{

System.out.println(“Masukan nilai=”);

Integer n=Integer.parseInt(dataIn.readLine());

if(n>=90&&n<=100)

{

System.out.println(“Nilai anda A”)

}

if(n>=75&&n<=89)

{

System.out.println(“Nilai anda B”);

}

if(n>=55&&n<=74)

{

System.out.println(“Nilai anda C”);

}

if(n>=35&&n<=54)

{

System.out.println(“Nilai anda D”);

}

if(n>=0&&n<=34)

{

System.out.println(“Nilai anda E”);

}

System.out.println(“coba lagi?”);

lagi=(char)dataIn.read();

}

while(lagi==’y’);

}

}

import java.io.*;

public class BilanganPrima

{

public static void main(String[] args)

{

int upperLimit = 30;

int lowerLimit = 0;

int counter = 0;

System.out.print(“Bilangan prima yang ada di antara ” +

lowerLimit + ” – ” + upperLimit + ” : “);

//cari bilangan prima yang terletak di antara

//upperLimit dan lowerLimit

for(int i=lowerLimit;i<=upperLimit;i++)

{

int factorCounter = 0;

//hitung jumlah faktor dari bilangan ini

for(int j=1;j<=i;j++)

{

if(i%j==0)

{

factorCounter++;

}

}

//jika jumlah faktor=2 berarti ini adalah bilangan prima

if(factorCounter==2)

{

counter++;

System.out.print(i + ” “);

}

}

if(counter==0)

System.out.println(“Tidak ada !”);

}

}

import java.io.*;

public class deret3

{

public static void main(String[]arg)

{

int x,y,i,jml;

float tot;

x=1;

y=2;

tot=0;

jml=5;

for(i=1;i<jml;i++)

{

System.out.print(“”+x+”/”+y+”+”);

tot=x/y;

x=x+1;

y=y+1;

}

System.out.print(“=”+tot);

}

}

import java.io.*;

public class fibo

{

public static void main(String[]arg)throws IOException

{

BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));

int c,i,d;

System.out.println(“masukan bilangan pertama=”);

int a=Integer.parseInt(dataIn.readLine());

System.out.println(“masukan bilangan kedua=”);

int b=Integer.parseInt(dataIn.readLine());

System.out.println(“”);

System.out.println(a);

System.out.println(b);

for(i=1;i<=3;i++)

{

c=a+b;

System.out.println(c);

a=b;

b=c;

}

}

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.*;

import java.lang.*;

public class mtk

{

public static void main(String[] arg) throws IOException

{

BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );

double a,b;

double c,d,e,f,g,h;

float x,y,z;

System.out.println(“\n\n”);

System.out.println(“OPERASI MATEMATIKA \n”);

System.out.print(“Masukkan Nilai a = “);

a = Double.parseDouble(dataIn.readLine());

System.out.print(“Masukkan Nilai b = “);

b = Double.parseDouble(dataIn.readLine());

System.out.print(“Masukkan Nilai x = “);

x = Float.parseFloat(dataIn.readLine());

System.out.print(“Masukkan Nilai y = “);

y = Float.parseFloat(dataIn.readLine());

c = a – b;

d = a + b;

e = a * b;

f = a/b;

z = x/y;

System.out.println(“\n\n”);

System.out.println(“Hasil a – b = ” + c);

System.out.println(“Hasil a + b = ” + d);

System.out.println(“Hasil a * b = ” + e);

System.out.println(“Hasil a / b = ” + f);

System.out.println(“Hasil x / y = ” + z);

}

}


import java.io.*;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.lang.*;

public class nilai_max

{

public static void main (String[] args) throws IOException

{

BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i,a;

int[] x = new int[5];

System.out.println (“Silahkan Input Data = “);

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

{

x[i]=Integer.parseInt(DataIn.readLine());

}

System.out.println(“\n”);

int max = x[0];

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

{

if (max < x[i])

{

max = x[i];

}

}

System.out.println(max);

}

}

import java.io.*;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.lang.*;

public class urutan_kecil

{

public static void main (String[] args) throws IOException

{

BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i, n;

int temp;

int[] x = new int[5];

System.out.println (“Silahkan Input Data = “);

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

{

x[i]=Integer.parseInt(DataIn.readLine());

}

System.out.println(“\n\n”);

for (n=0; n<=4; n++)

{

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

{

if (x[n] < x[i])

{

temp = x[i];

x[i] = x[n];

x[n] = temp;

}

}

}

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

{

System.out.println (x[i]);

}

}

}

import java.io.*;

public class genap

{

public static void main(String[]arg)throws IOException

{

BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));

int i,g,j,pilihan;

char lagi=’y’;

do

{

System.out.println(“1.genap”);

System.out.println(“2.ganjil”);

System.out.println(“3.keluar”);

System.out.println(“masukan pilihan anda=”);

pilihan=Integer.parseInt(dataIn.readLine());

if(pilihan==1)

{

System.out.println(“berapa kali?”);

int a=Integer.parseInt(dataIn.readLine());

System.out.println(“genap=”);

for(i=1;i<=a;i++)

{

g=i*2;

System.out.println(g);

}

}

else if(pilihan==2)

{

System.out.println(“berapa kali?”);

int b=Integer.parseInt(dataIn.readLine());

System.out.println(“ganjil=”);

for(i=1;i<=b;i++)

{

j=i*2-1;

System.out.println(j);

}

}

else if(pilihan==3)

{

System.exit(0);

}

else

{

System.out.println(“pilihan anda salah”);

}

System.out.println(“lagi?”);

lagi=(char)dataIn.read();

}

while(lagi==’y’);

}

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.*;

import java.lang.*;

import javax.swing.*;

import java.lang.String;

public class mtktugas

{

public static void main (String args[]) throws IOException

{

BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );

Double a,b;

Double c,d,e,f;

System.out.print(“Masukkan Nilai a = “);

a = Double.parseDouble(dataIn.readLine());

System.out.print(“Masukkan Nilai b = “);

b = Double.parseDouble(dataIn.readLine());

String pilihan=JOptionPane.showInputDialog (“Operator Matematika :\n1. Penjumlahan\n2.

Pengurangan\n3. Perkalian\n4. Pembagian\npress other 1-4 to exit”);

int pilih=Integer.parseInt (pilihan);

switch (pilih)

{

case 1 :

c = a + b;

System.out.println(“Hasil a + b = ” + c); break;

case 2 :

d = a – b;

System.out.println(“Hasil a – b = ” + d);

break;

case 3 :

e = a * b;

System.out.println(“Hasil a * b = ” + e);

break;

case 4 :

f = a/b;

System.out.println(“Hasil a / b = ” + f);

break;

default : System.out.println(“Maaf, menu tidak tersedia”);

break;

}

System.exit(0);

}

}

import java.io.*;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.lang.*;

public class urut_min

{

public static void main (String[] args) throws IOException

{

BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i,a;

int[] x = new int[5];

System.out.println (“Silahkan Input Data = “);

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

{

x[i]=Integer.parseInt(DataIn.readLine());

}

System.out.println(“\n”);

int max = x[0];

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

{

if (max > x[i])

{

max = x[i];

}

}

System.out.println(max);

}

}

import java.io.*;

public class deret2

{

public static void main(String[]arg)throws IOException

{

BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));

int i,c;

System.out.println(“diulang berapa kali?”);

int d=Integer.parseInt(dataIn.readLine());

System.out.println(“”);

for(i=1;i<d;i++)

{

System.out.print(i+”/”+(i+1)+” + “);

}

System.out.print(d+”/”+(i+1));

}

}

import java.io.*;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.lang.*;

public class urut_besar

{

public static void main (String[] args) throws IOException

{

BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i, n;

int temp;

int[] x = new int[5];

System.out.println (“Silahkan Input Data = “);

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

{

x[i]=Integer.parseInt(DataIn.readLine());

}

System.out.println(“\n\n”);

for (n=0; n<=4; n++)

{

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

{

if (x[n] > x[i])

{

temp = x[i];

x[i] = x[n];

x[n] = temp;

} }

}

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

{

System.out.println (x[i]);

}

}

}

import java.io.*;

public class HitungLuas

{

public static void main(String[] args)

{

//data segitiga

int panjangSegitiga = 5;

int tinggiSegiTiga = 9;

//data lingkaran

int jari2Lingkaran = 15;

//data bujursangkar

int panjangSisi = 13;

//data empat persegi panjang

int panjangPersegi = 35;

int lebarPersegi = 45;

//hitung luas

double luas;

//luas segitiga

luas = ((double)(panjangSegitiga*tinggiSegiTiga))/2;

System.out.println(“Luas Segitiga : ” + luas);

//luas lingkaran

luas = 3.14*jari2Lingkaran*jari2Lingkaran;

System.out.println(“Luas Lingkaran : ” + luas);

//luas bujursangkar

luas = panjangSisi*panjangSisi;

System.out.println(“Luas Bujursangkar : ” + luas);

//luas persegi panjang

luas = panjangPersegi*lebarPersegi;

System.out.println(“Luas Persegi Panjang : ” + luas);

}

}

package java2s;

import java.io.*;

class pswd

{

public static void main(String[] args) throws IOException

{

String user;

String pswd;

BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));

//System.out.print(‘\u000c’);

final int NUM_LINES = 100; // Just to be safe

for (int i = 0; i < NUM_LINES; i++) System.out.println();

System.out.println(“user Anda : “);

user = datain.readLine();

System.out.println(“pswd Anda : “);

pswd = datain.readLine();

if (user.equals(“ti-05”) && pswd.equals(“123”))

{

System.out.println(“anda berhak untuk login”);

}

else

{

System.out.println(“maaf anda tidak bisa login”);

}

System.out.println(“Nama Anda yaitu : “+user);

}

}

import java.io.*;

public class konversi

{

public static void main(String[]arg)throws IOException

{

BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));

float c,d,e,f;

System.out.println(“Menu Pilihan”);

System.out.println(“1.Penjumlahan”);

System.out.println(“2.Pengurangan”);

System.out.println(“3.Perkalian”);

System.out.println(“4.Pembagian”);

System.out.println(“masukan pilihan anda:”);

int pilihan=Integer.parseInt(dataIn.readLine());

if(pilihan==1)

{

System.out.println(“nilai a:”);

Float a=Float.parseFloat(dataIn.readLine());

System.out.println(“nilai b:”);

Float b=Float.parseFloat(dataIn.readLine());

c=a+b;

System.out.println(“hasil”+a+”+”+b+”=”+c);

}

if(pilihan==2)

{

System.out.println(“nilai a:”);

Float a=Float.parseFloat(dataIn.readLine());

System.out.println(“nilai b:”);

Float b=Float.parseFloat(dataIn.readLine());

d=a-b;

System.out.println(“hasil a-b=”+d);

}

if(pilihan==3)

{

System.out.println(“nilai a:”);

Float a=Float.parseFloat(dataIn.readLine());

System.out.println(“nilai b:”);

Float b=Float.parseFloat(dataIn.readLine());

e=a*b;

System.out.println(“hasil a*b=”+e);

}

if(pilihan==4)

{

System.out.println(“nilai a:”);

Float a=Float.parseFloat(dataIn.readLine());

System.out.println(“nilai b:”);

Float b=Float.parseFloat(dataIn.readLine());

f=a/b;

System.out.println(“hasil a/b=”+f);

}

}

}

import java.io.*;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.lang.*;

public class pencarian

{

public static void main (String[] args) throws IOException

{

BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i;

int a = 0;

int cari;

int[] x = new int[5];

System.out.println (“Silahkan Input Data = “);

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

{

x[i]=Integer.parseInt(DataIn.readLine());

}

System.out.println(“\n\n”);

System.out.print (“Angka berapa yang anda cari = “);

cari = Integer.parseInt(DataIn.readLine());

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

{

if (x[i] == cari)

{

a = a +1;

}

}

System.out.println(“\n\n”);

if (a == 0)

{

System.out.println (“Angka tidak ditemukan”);

}

else

System.out.println (“Angka ditemukan sebanyak ” + a);

}

}


import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.*;

import java.lang.*;

import javax.swing.*;

import java.lang.String;

public class indek

{

public static void main (String args[]) throws IOException

{

BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );

String grade;

String komen;

String nama, nim, kelas, semester;

Double uts, uas, tugas, absen, n;

System.out.print(“Nama anda = “);

nama = dataIn.readLine();

System.out.print(“NIM anda = “);

nim = dataIn.readLine();

System.out.print(“Kelas anda = “);

kelas = dataIn.readLine();

System.out.print(“Semester = “);

semester = dataIn.readLine();

System.out.print(“\n\n”);

System.out.print(“Nilai Komulatif (Indeks)\n”);

System.out.print(“Nilai UTS = “);

uts = Double.parseDouble(dataIn.readLine());

System.out.print(“Nilai UAS = “);

uas = Double.parseDouble(dataIn.readLine());

System.out.print(“Nilai TUGAS = “);

tugas = Double.parseDouble(dataIn.readLine());

System.out.print(“Nilai ABSENSI = “);

absen = Double.parseDouble(dataIn.readLine());

n = (uts + uas + tugas + absen) / 4;

if (n >=90 && n <=100)

{

grade = “A”;

komen = “Pertahankan prestasimu”;

}

else if (n >=75 && n <90)

{

grade = “B”;

komen = “Tingkatkan prestasimu lagi”;

}

else if (n >=55 && n <75)

{

grade = “C”;

komen = “Berusahalah untuk memperbaiki prestasimu lagi”;

}

else if (n >=35 && n <55)

{

grade = “D”;

komen = “Berusahalah lebih giat lagi tuk memperbaiki nilaimu”;

}

else

{

grade = “E”;

komen = “Ayo…semangat lagi dong”;

}

System.out.println(“Nilai anda = ” + n);

System.out.println(“Grade anda = ” + grade);

System.out.println(komen);

System.exit(0);

}

}

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: