Fat’s Albojongi

Just another WordPress.com weblog

Archive for the ‘java’ Category

tugas database

Posted by fatoni95 pada Februari 1, 2009


st1\:*{behavior:url(#ieooui) }
<!– /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:””; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; 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;}

//Listing Program inputdata.java

import java.io.*;

import java.sql.*;

public class database

{

static BufferedReader baca= new BufferedReader(new InputStreamReader(System.in));

static String nim, nama, alamat, kota;

static char hasil;

static String database = “jdbc:odbc:latihan”;

static Connection con;

static Statement stmt;

static ResultSet rs;

static int m;

static String query = “select * from mhs”;

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

{

do

{

System.out.println(“\n=====M E N U U T A M A=====”);

System.out.println(“1. Inpu Data”);

System.out.println(“2. Edit Data)”);

System.out.println(“3. Hapus Data”);

System.out.println(“4. Tampil Data”);

System.out.println(“0. Keluar”);

System.out.print(“Pilihan Anda : “);

m=Integer.parseInt(baca.readLine());

if (m==1)

{

input();

}

else if (m==3)

{

delete();

}

else if (m==4)

{

tampil();

}

}

while (m!=0);

}

//fungsi input

public static void input() throws IOException

{

try

{

Class.forName (“sun.jdbc.odbc.JdbcOdbcDriver”);

}

catch (java.lang.ClassNotFoundException e)

{

System.err.print(“ClassNotFoundException: “);

System.err.println(e.getMessage());

}

try

{

con = DriverManager.getConnection(database,””,””);

stmt = con.createStatement();

System.out.println(“\n:::::::::: Input Data ::::::::::”);

System.out.print(“Masukkan NIM : “);

nim=baca.readLine();

System.out.print(“Masukkan Nama : “);

nama=baca.readLine();

System.out.print(“Masukkan Alamat : “);

alamat=baca.readLine();

System.out.print(“Masukkan Kota : “);

kota=baca.readLine();

System.out.print(“Input Data ? (y/t)”);

hasil=(char)baca.read();

if ((hasil==’y’) || (hasil==’Y’))

{

stmt.executeUpdate(“insert into mhs (nim, nama, alamat, kota) values(“

+ “‘” + nim + “‘,”

+ “‘” +nama+ “‘,”

+ “‘” +alamat + “‘,”

+ “‘” +kota + “‘”

+ “)”);

}

else if ((hasil==’t’) || (hasil==’t’))

{

System.out.print(“Inputan Gagal”);

return;

}

else

{

System.out.print(“Inputan Salah!!! “);

return;

}

}

catch(SQLException ex)

{

System.err.println(“SQLException:”+ex.getMessage());

}

}

// fungsi tampil

public static void tampil()

{

try

{

Class.forName (“sun.jdbc.odbc.JdbcOdbcDriver”);

}

catch (java.lang.ClassNotFoundException e)

{

System.err.print(“ClassNotFoundException: “);

System.err.println(e.getMessage());

}

try

{

con = DriverManager.getConnection(database,””,””);

stmt = con.createStatement();

System.out.println(“\n!\n!::::::::: ========================= :::::::::”);

rs = stmt.executeQuery(query);

System.out.println(“\nDaftar Mahasiswa”);

while (rs.next())

{

String s1 = rs.getString(“nim”);

String s2 = rs.getString(“nama”);

String s3 = rs.getString(“alamat”);

String s4 = rs.getString(“kota”);

System.out.println(s1+ “ ” +s2+ “ ” +s3+ “ ” +s4);

}

stmt.close();

con.close();

}

catch(SQLException ex)

{

System.err.println(“SQLException:”+ex.getMessage());

}

}

// fungsi delete

public static void delete() throws IOException

{

try

{

Class.forName (“sun.jdbc.odbc.JdbcOdbcDriver”);

}

catch (java.lang.ClassNotFoundException e)

{

System.err.print(“ClassNotFoundException: “);

System.err.println(e.getMessage());

}

try

{

System.out.print(“nim yang akan dihapus : “);

nim=baca.readLine();

con = DriverManager.getConnection(database,””,””);

stmt = con.createStatement();

stmt.executeUpdate(“delete from mhs where nim=”+nim+””);

// ResultSet rs = stmt.executeQuery(query);

// System.out.println(“Daftar Mahasiswa”);

// while (rs.next())

// {

// String s1 = rs.getString(“nim”);

// String s2 = rs.getString(“nama”);

// String s3 = rs.getString(“alamat”);

// String s4 = rs.getString(“kota”);

// System.out.println(s1+ ” ” +s2+ ” ” +s3+ ” ” +s4);

// }

stmt.close();

con.close();

}

catch(SQLException ex)

{

System.err.println(“SQLException:”+ex.getMessage());

}

}

}

Iklan

Posted in java | Leave a Comment »

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);

}

}

Posted in java | Leave a Comment »

kuis 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”;} @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-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;}

KUIS JAVA STMIK CIC

import java.io.*;

public class Quiz

{

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

{

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

int p,l,k;

float m,km;

double rp,$;

int a,j,i;

int pilihan;

do

{

System.out.println(“MENU PILIHAN”);

System.out.println(“1.Keliling Persegi Panjang”);

System.out.println(“2.Konversi Jarak (m -> km)”);

System.out.println(“3.Kurs Mata Uang (Rp -> US$)”);

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

System.out.println(“0.Keluar”);

System.out.print(“Pilihan Anda??”);

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

if(pilihan==1)

{

System.out.print(“Masukkan Panjang: “);

p=Integer.parseInt(datain.readLine());

System.out.print(“Masukkan Lebar: “);

l=Integer.parseInt(datain.readLine());

k=(2*p)+(2*l);

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

System.out.println(“Keliling Persegi Panjang Adalah : “+k);

}

else if(pilihan==2)

{

System.out.print(“Masukkan Panjang M: “);

m=Float.parseFloat(datain.readLine());

km=m/1000;

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

System.out.println(m+” Meter = “+km+” Kilometer”);

}

else if(pilihan==3)

{

System.out.print(“Masukkan Nilai Rp: “);

rp=Double.parseDouble(datain.readLine());

$=rp/11400;

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

System.out.println(“Rp “+rp+”= US$ “+$);

}

else if(pilihan==4)

{

System.out.print(“Nilai Awal: “);

a=Integer.parseInt(datain.readLine());

System.out.print(“Jumlah Deret: “);

j=Integer.parseInt(datain.readLine());

System.out.print(a+””);

j=j-1;

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

{

a=a-2;

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

}

}

else

System.out.println(“Data yang Anda Masukkan Error!!!”);

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

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

System.out.println(“Thank you from Deni Iskandar”);

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

}

while(pilihan!=0);

}

}

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 Quizjava1

{

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

{

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

double p,l,kll;

double m,km;

double rp,dol;

double der,a,i,z;

System.out.print(“*****MENU UTAMA*****”);

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

System.out.println(“1. Keliling Persegi Panjang”);

System.out.println(“2. Konversi Jarak (meter ==> kilometer”);

System.out.println(“3. Kurs Mata Uang (Rp ==> US$”);

System.out.println(“4. Deret Mundur (-2)”);

System.out.println(“0. Keluar”);

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

String pilihan=JOptionPane.showInputDialog (“*****MENU UTAMA ***** :\n\n1.

Keliling Persegi Panjang\n2. Konversi Jarak (M==>KM)\n3. Kurs Mata Uang

(Rp==>US$)\n4. Deret\n0. Exit\n Pilihan Anda = “);

int pilih=Integer.parseInt (pilihan);

switch (pilih)

{

case 1 :

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

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

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

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

kll=(p+l)*2;

System.out.println(“Keliling persegi panjang adalah = ” + kll);

break;

case 2 :

System.out.print(“Masukkan Ukuran dalam Meter = “);

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

km = m / 1000;

System.out.println(m + ” meter = ” + km + ” kilometer”); break;

case 3 :

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

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

dol = rp / 11400;

System.out.println(rp + ” rupiah = ” + dol + ” US$”);

break;

case 4 :

System.out.print(“Masukkan Suku Ke-1 = “);

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

System.out.print(“Mau Diulang berapa kali = “);

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

System.out.println(a);

for (i=2;i<=der;i++)

{

for (z=2;z<=der;z++)

{

i=a-2;

System.out.println(i);

a=i;

if (i==0)

{

System.exit(0);

}

}

}

break;

case 0 :

System.out.println(“Bye…bye…..”);

break;

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

break;

}

System.exit(0);

}

}

Posted in java | Leave a Comment »

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);

}

}

Posted in java | Leave a Comment »

prosedur dan fungsi di java

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”;} @page Section1 {size:612.1pt 936.1pt; margin:56.7pt 56.7pt 155.95pt 56.7pt; mso-header-margin:.5in; mso-footer-margin:.5in; 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;}

Prosedur

import java.io.*;

class demosepeda

{

public static void main (String[ ] args)

{

sepedagunung spd = new sepedagunung();

spd.ubahgear(10);

spd.tambahspeed(50);

spd.ubahsadle(15);

spd.tampil();

spd.tampilsadle();

}

}

import java.io.*;

class sepedagunung extends sepeda

{

int sadle = 0;

public void ubahsadle (int tinggi)

{

sadle = sadle + tinggi;

}

public void tampilsadle()

{

System.out.println (“Tinggi sadle sepeda = ” + sadle);

}

}

import java.io.*;

class sepeda

{

int speed = 0;

int gear = 0;

public void ubahgear (int ubah)

{

gear = gear + ubah;

}

public void tambahspeed (int tambah)

{

speed = speed + tambah;

}

public void tampil()

{

System.out.println (“Gear = ” + gear + ” kecepatan = ” + speed);

}

}

import java.io.*;

class demomobil

{

public static void main (String[] args)

{

bus spd = new bus();

spd.ubahgear(7);

spd.tambahspeed(150);

spd.tampil();

spd.hiduptv();

spd.carichanel();

spd.tampilgambar();

}

}

import java.io.*;

class bus extends mobil

{

public void hiduptv ()

{

System.out.println (“TV Dihidupkan”);

}

public void carichanel ()

{

System.out.println (“Chanel sudah dicari”);

}

public void tampilgambar ()

{

System.out.println (“Gambar sudah ditampilkan”);

}

}

import java.io.*;

class mobil

{

int speed = 0;

int gear = 0;

public void ubahgear (int ubah)

{

gear = gear + ubah;

}

public void tambahspeed (int tambah)

{

speed = speed + tambah;

}

public void tampil()

{

System.out.println (“Gear = ” + gear + ” kecepatan = ” + speed);

}

}


import coba.latihanexe;

import coba.latihanexe2;

class packagess

{

public static void main (String[] arg)

{

latihanexe lat = new latihanexe();

latihanexe2 lat2 = new latihanexe2();

lat.tampil();

lat2.tampil2();

}

}

package coba;

public class latihanexe

{

public void tampil()

{

System.out.println (“Belajar membuat package”);

}

}

package coba;

public class latihanexe2

{

public void tampil2()

{

System.out.println (“Belajar membuat package 2”);

}

}


import java.io.*;

class matematika

{

//bilangan bulat

public int tambah (int x, int y)

{

return x + y;

}

public int kurang (int x, int y)

{

return x – y;

}

public int kali (int x, int y)

{

return x * y;

}

public int bagi (int x, int y)

{

return x / y;

}

//bilangan pecahan

public double tambah (double x, double y)

{

return x + y;

}

public double kurang (double x, double y)

{

return x – y;

}

public double kali (double x, double y)

{

return x * y;

}

public double bagi (double x, double y)

{

return x / y;

}

}

class tulis

{

public void tampil()

{

System.out.println(“Hallo”);

}

}

class panggilan

{

public static void main (String args[])

{

tulis x = new tulis();

x.tampil();

//manggil class dari file matematika

matematika m = new matematika();

//bilangan bulat

System.out.println (“Hasil = ” + m.tambah (5,5));

System.out.println (“Hasil = ” + m.kurang (5,5));

System.out.println (“Hasil = ” + m.kali (5,5));

System.out.println (“Hasil = ” + m.bagi (5,5));

//bilangan pecahan

System.out.println (“Hasil = ” + m.tambah (5.5,2.5));

System.out.println (“Hasil = ” + m.kurang (5.5,2.5));

System.out.println (“Hasil = ” + m.kali (5.5,2.5));

System.out.println (“Hasil = ” + m.bagi (5.5,2.5));

}

}

Posted in java | Leave a Comment »

perulangan (for … while …. do)

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”;} @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-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;}

PERULANGAN

import java.io.*;

class ulang3

{

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

{

int i;

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

i=1;

do

{

System.out.println(“Perulangan Ke-“+i);

i++;

}

while (i<=5);

}

}

import java.io.*;

class ulang2

{

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

{

int i;

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

i=1;

while (i<=5)

{

System.out.println(“Perulangan Ke-“+i);

i++;

}

}

}

import java.io.*;

class ulang1

{

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

{

int i;

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

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

{

System.out.println(“Perulangan Ke-“+i);

}

}

}


import java.io.*;

public class perulangan1

{

public static void main(String[]arg)

{

int i;

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

{

System.out.println(i);

}

}

}

import java.io.*;

public class percabangan1

{

public static void main(String[]arg)

{

String names[] = {“Beah”, “Bianca”, “Lance”, “Belle”, “Nico”, “Gem”, “Ethan”};

String searchName = “Yza”;

boolean foundName = false;

for( int i=0; i< names.length; i++ )

{

if( names[i].equals( searchName ))

{

foundName = true;

break;

}

}

if( foundName=true )

{

System.out.println( searchName + ” found!” );

}

if( foundName=false )

{

System.out.println( searchName + ” not found.” );

}

}

}

Posted in java | Leave a Comment »

pemilihan if dan else

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”;} @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-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;}

PEMILIHAN (IF …. ELSE)

import java.io.*;

public class pemilihan3

{

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

{

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

char x;

System.out.println(“input sebuah karakter:”);

x=(char)dataIn.read();

if(x==’a’)

{

System.out.println(“anda benar”);

}

else

{

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

}

}

}

import java.io.*;

public class pemilihan1

{

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

{

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

int x;

System.out.println(“input sebuah bilangan:”);

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

if(x>10)

{

System.out.println(“anda benar”);

}

else

{

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

}

}

}

import java.io.*;

public class pemilihan2

{

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

{

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

String nama,jurusan;

System.out.println(“nama anda:”);

nama=dataIn.readLine();

System.out.println(“jurusan:”);

jurusan=dataIn.readLine();

if(nama.equals(“STMIK”)&&jurusan.equals(“TI”))

{

System.out.println(“Anda benar”);

}

else

{

System.out.println(“Anda salah”);

}

}

}

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 ifa

{

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;

String p;

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.println (“Menu Operator Matematika \n”);

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

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

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

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

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

System.out.print(“Pilihan anda? = “);

p = dataIn.readLine();

if (p = “1”)

{

c = a + b;

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

}

else if (p = “2”)

{

d = a – b;

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

}

else if (p = “3”)

{

e = a * b;

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

}

else

{

f = a/b;

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

}

}

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.*;

import java.lang.*;

public class if

{

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;

string p;

//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());

//z = x/y;

System.out.println (“Menu Operator Matematika \n”);

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

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

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

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

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

System.out.print(“Pilihan anda? = “);

p = dataIn.readLine();

if (p = 1)

{

c = a + b;

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

}

else if (p = 2)

{

d = a – b;

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

}

else if

{

e = a * b;

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

}

else

{

f = a/b;

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

}

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

}

}


PEMILIHAN (CASE)

import java.io.*;

class selek5

{

static char indeks;

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

{

char x;

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

System.out.println(“Input Karakter : “);

x = (char) datain.read();

switch(x)

{

case ‘a’ : indeks = ‘A’;break;

case ‘b’ : indeks = ‘B’;break;

case ‘c’ : indeks = ‘C’;break;

case ‘d’ : indeks = ‘D’;break;

case ‘e’ : indeks = ‘E’;break;

default : indeks = ‘T’;

}

System.out.println(“Indeks Nilai : “+indeks);

}

}

import java.io.*;

class selek4

{

static char indeks;

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

{

int uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Integer.parseInt(datain.readLine());

System.out.println(“Nilai UAS : “);

uas = Integer.parseInt(datain.readLine());

na = (uts+uas)/2;

switch(na)

{

case 100 :

case 90: indeks = ‘A’;break;

case 75 : indeks = ‘B’;break;

case 60 : indeks = ‘C’;break;

case 45 : indeks = ‘D’;break;

case 0 : indeks = ‘E’;break;

default : indeks = ‘T’;

}

System.out.println(“Nilai Akhir yaitu : “+na);

System.out.println(“Indeks Nilai : “+indeks);

}

}

import java.io.*;

class selek3

{

static char indeks;

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

{

float uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Float.parseFloat(datain.readLine());

System.out.println(“Nilai UAS : “);

uas = Float.parseFloat(datain.readLine());

na = (uts+uas)/2;

if (na>=90)

{

indeks = ‘A’;

}

else if (na>=75)

{

indeks = ‘B’;

}

else if (na>=60)

{

indeks = ‘C’;

}

else if (na>=45)

{

indeks = ‘D’;

}

else if (na>=0)

{

indeks = ‘E’;

}

System.out.println(“Nilai Akhir yaitu : “+na);

System.out.println(“Indeks Nilai : “+indeks);

}

}

import java.io.*;

import java.lang.*;

class selek2

{

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

{

float uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Float.parseFloat(datain.readLine());

//uts = Float.valueOf(datain.readLine).floatValue();

System.out.println(“Nilai UAS : “);

uas = Float.parseFloat(datain.readLine());

na = (uts+uas)/2;

if (na>=90)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : A”);

}

else if (na>=75)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : B”);

}

else if (na>=60)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : C”);

}

else if (na>=45)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : D”);

}

else if (na>=0)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : E”);

}

}

}


import java.io.*;

class selek1

{

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

{

String nama;

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(“Nama Anda : “);

nama = datain.readLine();

if (nama.equals(“deny”))

{

System.out.println(“Anda Benar”);

} else

{

System.out.println(“Anda Salah”);

}

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

}

}

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 pilih4

{

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

{

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

char k;

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

k = (char) dataIn.read();

if (k == ‘d’)

{

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

}

else

{

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

}

}

}

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 pilih2

{

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

{

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

String nama;

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

nama = dataIn.readLine();

if (nama.equals (“fatoni”))

{

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

}

else

{

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

}

}

}

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 pilih3

{

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

{

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

String nama;

String jurusan;

String kampus;

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

nama = dataIn.readLine();

System.out.print(“Jurusan kuliah = “);

jurusan = dataIn.readLine();

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

kampus = dataIn.readLine();

if (nama.equals (“fatoni”) && jurusan.equals (“TI”) && kampus.equals (“STMIK CIC”))

{

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

}

else

{

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

}

}

}

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 pilih

{

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

{

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

int x;

System.out.print(“Input sebuah bilangan = “);

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

if (x > 10)

{

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

}

else

{

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

}

}

}

import java.io.*;

class caseindex

{

static char indeks;

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

{

int uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Integer.parseInt(datain.readLine());

System.out.println(“Nilai UAS : “);

uas = Integer.parseInt(datain.readLine());

na = (uts+uas)/2;

switch(na)

{

case 100 : indeks = ‘A+’;break;

case 90: indeks = ‘A’;break;

case 75 : indeks = ‘B’;break;

case 60 : indeks = ‘C’;break;

case 45 : indeks = ‘D’;break;

case 0 : indeks = ‘E’;break;

default : indeks = ‘T’;

}

System.out.println(“Nilai Akhir yaitu : “+na);

System.out.println(“Indeks Nilai : “+indeks);

}

}

import java.io.*;

import java.lang.*;

class indeknilai {

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

float uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Float.parseFloat(datain.readLine());

//uts = Float.valueOf(datain.readLine).floatValue();

System.out.println(“Nilai UAS : “);

uas = Float.parseFloat(datain.readLine());

na = (uts+uas)/2;

if (na>=90)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : A”);

} else

if (na>=75)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : B”);

} else

if (na>=60)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : C”);

} else

if (na>=45)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : D”);

} else

if (na>=0)

{

System.out.println(“Nilai Akhir : “+na);

System.out.println(“Indeks Nilai : E”);

}

}

}

import java.io.*;

class indexnilai2 {

static char indeks;

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

float uts,uas,na;

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

System.out.println(“Nilai UTS : “);

uts = Float.parseFloat(datain.readLine());

System.out.println(“Nilai UAS : “);

uas = Float.parseFloat(datain.readLine());

na = (uts+uas)/2;

if (na>=90)

{

indeks = ‘A’;

} else

if (na>=75)

{

indeks = ‘B’;

} else

if (na>=60)

{

indeks = ‘C’;

} else

if (na>=45)

{

indeks = ‘D’;

} else

if (na>=0)

{

indeks = ‘E’;

}

System.out.println(“Nilai Akhir yaitu : “+na);

System.out.println(“Indeks Nilai : “+indeks);

}

}

Posted in java | Leave a Comment »

hallo java

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”;} @page Section1 {size:612.1pt 936.1pt; margin:113.4pt 85.05pt 170.1pt 113.4pt; mso-header-margin:.5in; mso-footer-margin:127.6pt; 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;}

HALLO JAVA

public class hallo

{

public static void main (String[] arg)

{

//Lokal Deklarasi

String k=” Cirebon”;

System.out.println (“Hallo Java”);

System.out.println (“STMIK CIC” + k);

}

}

public class hallo

{

public static void main (String[] arg)

{

System.out.println (“Hallo Java”);

System.out.println (“STMIK CIC”);

}

}

Posted in java | Leave a Comment »

contoh sourcecode gambar bintang dengan java

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”;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; 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;}

GAMBAR BINTANG

import java.io.*;

public class bintangm

{

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

{

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

int i,j;

System.out.println(“berapa jumlah baris=”);

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

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

{

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

{

System.out.print(” * “);

}

System.out.println();

}

}

}

import java.io.*;

public class Bintangsamasisi

{

public static void main(String[] args)

{

int ukuran = 7;

for(int i=0;i<ukuran;i++)

{

int j;

int spasiCounter = ukuran-i-1;

for(j=0;j<spasiCounter;j++)

{

System.out.print(” “);

}

for(j=0;j<=(i*2);j++)

{

if(j%2==1)

System.out.print(” “);

else

System.out.print(“*”);

}

System.out.println();

}

}

}

Posted in java | Leave a Comment »

Contoh source code Array

Posted by fatoni95 pada Februari 1, 2009

ARRAY

public class array
{
public static void main (String[] args)
{
// dalam menentukan varabel array
// ada dua cara yaitu :
// 1. int[] no;
// int no[5];
// no = new int[5];
// 2. int[] no = new int[5];

int i;
int [] no = new int[5];
for (i=1; i<=5; i++)
{
no[i]=i;
}
for (i=1; i<=5; i++)
{
System.out.println(no[i]);
}
}
}

public class Array2
{
public static void main(String[] args)
{
int nilai[]={70,80,90,100,20,70,65,25};

for (int i=0;i<nilai.length;i++)
{
if (i%2==0)
System.out.print(nilai[i]+ " ");
}
}
}

public class Array4
{
public static void main(String[] args)
{
int nilai[]={70,80,90,100,20,70,65,25};
int total=0;double rata;
System.out.print(" " );
for (int i=0;i<nilai.length;i++)
{
total=total+nilai[i];
System.out.print( nilai[i]+ " + " );
}
rata=total/nilai.length;
System.out.println("="+total);
System.out.print(rata);
}
}

public class Array5
{
public static void main(String[] args)
{
int nilai[]={70,80,90,100,20,70,65,25};
for (int i=0;i<nilai.length;i++)
{
if(nilai[i]==100)
{
System.out.print("Nilai " + nilai[3]+ " untuk mahasiswa tsb ada pada index "+i );
}
}
}
}

public class Array6
{
public static void main(String[] args)
{
int nilai[] = {70,80,90,100,20,70,65,25};
System.out.print("\n");
int maks = 0;
for (int i=0;i maks)
{
maks = nilai[i];
}
}
System.out.print(“\n”);
System.out.print(“Nilai Maksimal = “+maks);
}
}

public class Array7
{
public static void main(String[] args)
{
int nilai[] = {70,80,90,100,20,70,65,25};
System.out.print(“\n”);
int min = 100;
for (int i=0;i<nilai.length;i++)
{
if (nilai[i] < min)
{
min = nilai[i];
}
}
System.out.print("\n");

System.out.print("Nilai Minimum = "+min);
}
}

import java.io.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.*;

public class array21
{
public static void main (String[] args) throws IOException
{
BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));
int i,a;
int[] no = new int[5];
System.out.println ("Silahkan Input Data = ");
for (i=0; i<5; i++)
{
no[i]=Integer.parseInt(DataIn.readLine());
}
System.out.println("\n");
for (i=0; i<5; i++)
{
System.out.println(no[i]);
}
}
}

import java.io.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.*;

public class array31
{
public static void main (String[] args) throws IOException
{
BufferedReader DataIn = new BufferedReader (new InputStreamReader(System.in));

int i,a;
int[] no = new int[5];
no[0]=1;
no[1]=2;
no[2]=3;
no[3]=4;
no[4]=5;

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

Posted in java | Leave a Comment »