programnya:
public class bubbleSort{
public static void main(String a[]){
int i;
int array[] = {90,70,95,10,85,100,50,68,30,25};
System.out.println("Nilai Awal:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
bubble_srt(array, array.length);
System.out.print("Setelah diurutkan:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
System.out.println("");
}
public static void bubble_srt( int a[], int n ){
int i, j,t=0;
for(i = 0; i < n; i++){
for(j = 1; j < (n-i); j++){
if(a[j-1] > a[j]){
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}
}
hasil programnya:
Minggu, 15 Mei 2011
Buble sort(Program C++)
Programnya:
#include"iostream.h"
void main(){
int bil[]={70,50,90,30,60,65,10};
int temp;
int j,i,n=7;
cout<<"Nilai awal:"<<endl;
for(i=0;i<n;i++) cout<<bil[i]<<" "<<endl;
for(i=0;i<n-1;i++){'pengurutan'
for(j=n-1;j>=i+1;j--){
if(bil[j] < bil[j-1])
temp=bil[j]; 'untuk memindahkan data sebelah kiri-
'kesebelah kanam'
bil[j]=bil[j-1];
bil[j-1]=temp;
}
}
}
cout<<endl;
cout<<"setelah diurut:"<<endl ;
for(i=0;i<n;i++)
cout<<bil[i]<< " "<<endl;
}
Hasinya programnya:
#include"iostream.h"
void main(){
int bil[]={70,50,90,30,60,65,10};
int temp;
int j,i,n=7;
cout<<"Nilai awal:"<<endl;
for(i=0;i<n;i++) cout<<bil[i]<<" "<<endl;
for(i=0;i<n-1;i++){'pengurutan'
for(j=n-1;j>=i+1;j--){
if(bil[j] < bil[j-1])
temp=bil[j]; 'untuk memindahkan data sebelah kiri-
'kesebelah kanam'
bil[j]=bil[j-1];
bil[j-1]=temp;
}
}
}
cout<<endl;
cout<<"setelah diurut:"<<endl ;
for(i=0;i<n;i++)
cout<<bil[i]<< " "<<endl;
}
Hasinya programnya:
Minggu, 08 Mei 2011
program Rata.java
Tugas ke-empat
Mencari nilai rata-rata,nilai tertinggi dan nilai terendah dengan menggunakan program java
import java.io.*;
public class rata{
public static void main(String Arg[])throws IOException{
int Nilai[];
Nilai=new int[20];
double rata=0,total=0;
int nmax=0;int nmin=1000;
String str;
int i,jdata;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.println("menghitung Nilai");
System.out.print("jumlah data:");str=Get.readLine();
jdata=Integer.parseInt(str);
for(i=0;i<jdata;i++){
System.out.print("Nilai ke:"+(i+1)+":");
str=Get.readLine();
Nilai[i]=Integer.parseInt(str);
}
rata=0;total=0;
for(i=0;i<jdata;i++){
System.out.println("Nilai ke:"+(i+1)+":"+Nilai[i]);
total=total+Nilai[i];
if(Nilai[i]>nmax)nmax=Nilai[i];
if(Nilai[i]<nmin)nmin=Nilai[i];
}
rata=total/jdata;
System.out.println("Nilai rata-rata:"+rata);
System.out.println("Nilai tertinggi:"+nmax);
System.out.println("Nilai terendah:"+nmin);
}
}
Hasil programnya:
Mencari nilai rata-rata,nilai tertinggi dan nilai terendah dengan menggunakan program java
import java.io.*;
public class rata{
public static void main(String Arg[])throws IOException{
int Nilai[];
Nilai=new int[20];
double rata=0,total=0;
int nmax=0;int nmin=1000;
String str;
int i,jdata;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.println("menghitung Nilai");
System.out.print("jumlah data:");str=Get.readLine();
jdata=Integer.parseInt(str);
for(i=0;i<jdata;i++){
System.out.print("Nilai ke:"+(i+1)+":");
str=Get.readLine();
Nilai[i]=Integer.parseInt(str);
}
rata=0;total=0;
for(i=0;i<jdata;i++){
System.out.println("Nilai ke:"+(i+1)+":"+Nilai[i]);
total=total+Nilai[i];
if(Nilai[i]>nmax)nmax=Nilai[i];
if(Nilai[i]<nmin)nmin=Nilai[i];
}
rata=total/jdata;
System.out.println("Nilai rata-rata:"+rata);
System.out.println("Nilai tertinggi:"+nmax);
System.out.println("Nilai terendah:"+nmin);
}
}
Hasil programnya:
Senin, 02 Mei 2011
program lat6.java
Tugas ketiga
import java.io.*;
public class lat6{
public static void main(String Arg[])throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP=Get.readLine();
System.out.print("Nama :");Nama=Get.readLine();
System.out.print("kode :");str=Get.readLine();
Kdj=Integer.parseInt(str);
if(Kdj==1){
jbt="Direktur";gaji=5000000;
}else if(Kdj==2){
jbt="wakil direktur";gaji=4000000;
}else if(Kdj==3){
jbt="bendahara";gaji=3000000;
}else if(Kdj==4){
jbt="staf";gaji=2000000;
}else{
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("jabatan :"+jbt);
System.out.println("gaji :"+gaji);
System.out.println("pajak :"+pajak);
System.out.println("total :"+total);
}
}
Hasilnya:
import java.io.*;
public class lat6{
public static void main(String Arg[])throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP=Get.readLine();
System.out.print("Nama :");Nama=Get.readLine();
System.out.print("kode :");str=Get.readLine();
Kdj=Integer.parseInt(str);
if(Kdj==1){
jbt="Direktur";gaji=5000000;
}else if(Kdj==2){
jbt="wakil direktur";gaji=4000000;
}else if(Kdj==3){
jbt="bendahara";gaji=3000000;
}else if(Kdj==4){
jbt="staf";gaji=2000000;
}else{
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("jabatan :"+jbt);
System.out.println("gaji :"+gaji);
System.out.println("pajak :"+pajak);
System.out.println("total :"+total);
}
}
Hasilnya:
program lat7.java
import java.io.*;
public class lat7{
public static void main(String Arg[])throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP=Get.readLine();
System.out.print("Nama :");Nama=Get.readLine();
System.out.print("kode :");str=Get.readLine();
Kdj=Integer.parseInt(str);
switch(Kdj){
case 1:jbt="Direktur";gaji=5000000;
break;
case 2:jbt="wakil direktur";gaji=4000000;
break;
case 3:jbt="bendahara";gaji=3000000;
break;
case 4:jbt="staf";gaji=2000000;
break;
default:
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("jabatan :"+jbt);
System.out.println("gaji :"+gaji);
System.out.println("pajak :"+pajak);
System.out.println("total :"+total);
}
}
Hasilnya:
public class lat7{
public static void main(String Arg[])throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP=Get.readLine();
System.out.print("Nama :");Nama=Get.readLine();
System.out.print("kode :");str=Get.readLine();
Kdj=Integer.parseInt(str);
switch(Kdj){
case 1:jbt="Direktur";gaji=5000000;
break;
case 2:jbt="wakil direktur";gaji=4000000;
break;
case 3:jbt="bendahara";gaji=3000000;
break;
case 4:jbt="staf";gaji=2000000;
break;
default:
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("jabatan :"+jbt);
System.out.println("gaji :"+gaji);
System.out.println("pajak :"+pajak);
System.out.println("total :"+total);
}
}
Hasilnya:
program loop2.java
class loop2{
public static void main(String Arg[]) {
int i=1 ;
do{
System.out.println(i) ;
i++ ;
}while( i != 11);
}
}
Hasilnya:
public static void main(String Arg[]) {
int i=1 ;
do{
System.out.println(i) ;
i++ ;
}while( i != 11);
}
}
Hasilnya:
program loop4.java
import java.io.* ;
class loop4{
public static void main(String Arg[]) throws IOException {
int pil,l,s,r,p ;
double ls, vol ;
String str ;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in)) ;
do{
System.out.println("Menu Utama");
System.out.println("1.Hitung Volume Kubus");
System.out.println("2.Hitung Luas");
System.out.println("3.Hitung LUas Lingkaran");
System.out.println("4.Keluar Program") ;
System.out.print("Pilihan Anda:");str=Get.readLine();
pil = Integer.parseInt(str) ;
switch(pil){
case 1:
System.out.println("Menghitung Volume Kubus");
System.out.print("Sisi:");str=Get.readLine();
s = Integer.parseInt(str) ;
vol = s*s*s;
System.out.println("Volume Kubus:"+vol);
break;
case 2:
System.out.println("Menghitung Luas Persegi Panjang");
System.out.print("Lebar:");str=Get.readLine();
l=Integer.parseInt(str);
System.out.print("Panjang:");str=Get.readLine();
p = Integer.parseInt(str) ;
ls = p*l;
System.out.println("Luas Persegi Panjang:"+ls);
break;
case 3:
System.out.println("Menghitung Luas Lingkaran");
System.out.print("Jari Jari:");str=Get.readLine();
r = Integer.parseInt(str);
ls = 3.14*r*r;
System.out.print("Luas Lingkaran:"+ls);
break;
}
str=Get.readLine();
}while(pil!= 4);
}
}
Hasilnya:
class loop4{
public static void main(String Arg[]) throws IOException {
int pil,l,s,r,p ;
double ls, vol ;
String str ;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in)) ;
do{
System.out.println("Menu Utama");
System.out.println("1.Hitung Volume Kubus");
System.out.println("2.Hitung Luas");
System.out.println("3.Hitung LUas Lingkaran");
System.out.println("4.Keluar Program") ;
System.out.print("Pilihan Anda:");str=Get.readLine();
pil = Integer.parseInt(str) ;
switch(pil){
case 1:
System.out.println("Menghitung Volume Kubus");
System.out.print("Sisi:");str=Get.readLine();
s = Integer.parseInt(str) ;
vol = s*s*s;
System.out.println("Volume Kubus:"+vol);
break;
case 2:
System.out.println("Menghitung Luas Persegi Panjang");
System.out.print("Lebar:");str=Get.readLine();
l=Integer.parseInt(str);
System.out.print("Panjang:");str=Get.readLine();
p = Integer.parseInt(str) ;
ls = p*l;
System.out.println("Luas Persegi Panjang:"+ls);
break;
case 3:
System.out.println("Menghitung Luas Lingkaran");
System.out.print("Jari Jari:");str=Get.readLine();
r = Integer.parseInt(str);
ls = 3.14*r*r;
System.out.print("Luas Lingkaran:"+ls);
break;
}
str=Get.readLine();
}while(pil!= 4);
}
}
Hasilnya:
Minggu, 01 Mei 2011
program loop.java
Langganan:
Postingan (Atom)