Sie sind auf Seite 1von 14

MODUL 7

PERULANGAN DENGAN WHILE


SOAL 1
Source Code :

package pkg1814311020; _________________________________________


import java.util.Scanner; _________________________________________
_________________________________________
public class Modul7 { _________________________________________
public static void main(String[] args) { _________________________________________
_________________________________________
Scanner masuk=new Scanner(System.in); _________________________________________
int i; _________________________________________
_________________________________________
float n,x,jum,rata; _________________________________________
System.out.print("Banyaknya data :"); _________________________________________
_________________________________________
n=masuk.nextFloat();
_________________________________________
_________________________________________
_________________________________________
jum=0;
_________________________________________
for(i=1;i<=n;i++){ _________________________________________
_________________________________________
System.out.println("Data ke-
_________________________________________
"+i+":");
_________________________________________
x=masuk.nextFloat(); _________________________________________
_________________________________________
jum+=x;
_________________________________________
} _________________________________________
_________________________________________
_________________________________________
rata=jum/n; _________________________________________
System.out.println("Rata-rata :"+ _________________________________________
rata); _________________________________________
_________________________________________
System.out.println("jumlah :"+jum); _________________________________________
System.out.println(""); _________________________________________
_________________________________________
System.out.println("Nama : Roni _________________________________________
ALmuzadi"); _________________________________________
System.out.println("NIM : _________________________________________
1814311020"); _________________________________________
_________________________________________
}
_________________________________________
} _________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________

Hasil / Output :
MODUL 8
PERULANGAN DENGAN DO WHILE
SOAL 1
Source Code :
package pkg1814311020; _______________________________________
_______________________________________
_______________________________________
import java.util.Scanner; _______________________________________
public class Modul8 { _______________________________________
_______________________________________
public static void main(String[] args) { _______________________________________
Scanner masuk=new Scanner(System.in); _______________________________________
_______________________________________
int i; _______________________________________
float n,x,jum,rata; _______________________________________
_______________________________________
System.out.print("Banyaknya data :"); _______________________________________
n=masuk.nextFloat(); _______________________________________
_______________________________________
_______________________________________
jum=0; _______________________________________
_______________________________________
for(i=1;i<=n;i++){ _______________________________________
System.out.println("Data ke-"+i+":"); _______________________________________
_______________________________________
x=masuk.nextFloat();
_______________________________________
jum+=x; _______________________________________
_______________________________________
}
_______________________________________
while (i<=n); _______________________________________
_______________________________________
rata=jum/n;
_______________________________________
System.out.println("Rata-rata :"+ rata); _______________________________________
_______________________________________
System.out.println("jumlah :"+jum);
_______________________________________
System.out.println(""); _______________________________________
_______________________________________
System.out.println("Nama : Roni
ALmuzadi"); _______________________________________
_______________________________________
System.out.println("NIM : _______________________________________
1814311020"); _______________________________________
} _______________________________________
_______________________________________
} _______________________________________
_______________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________

Hasil / Output :
MODUL 9
PERULANGAN DENGAN FOR
SOAL 1
Source Code :

package pkg1814311020; _____________________________________


public class Modul9 { _____________________________________
_____________________________________
public static void main(String[] args) { _____________________________________
int bil,jumlah; _____________________________________
_____________________________________
jumlah=0; _____________________________________
for(bil=0;bil<100;bil++){ _____________________________________
_____________________________________
System.out.println(bil); _____________________________________
jumlah +=bil; _____________________________________
_____________________________________
System.out.println("Jumlah:"+jumlah); _____________________________________
_____________________________________
_____________________________________
} _____________________________________
System.out.println(""); _____________________________________
_____________________________________
System.out.println("Nama : Roni
_____________________________________
Almuzadi");
_____________________________________
System.out.println("NIM : _____________________________________
1814311020"); _____________________________________
_____________________________________
}
_____________________________________
} _____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
_____________________________________
Hasil / Output :
SOAL 2
Source Code :
package pkg1814311020; ______________________________________
______________________________________
______________________________________
import java.util.Scanner; ______________________________________
public class Modul9_No2 { ______________________________________
______________________________________
public static void main(String[] args) { ______________________________________
Scanner masuk=new Scanner(System.in); ______________________________________
______________________________________
int bil,a,b; ______________________________________
System.out.print("Masukkan Batas Awal :"); ______________________________________
______________________________________
a=masuk.nextInt(); ______________________________________
System.out.print("Masukkan Batas Akhir :"); ______________________________________
______________________________________
b=masuk.nextInt(); ______________________________________
for(bil=a;bil<=b;bil++){ ______________________________________
______________________________________
if(bil%2!=0) ______________________________________
System.out.println(bil); ______________________________________
______________________________________
______________________________________
} ______________________________________
______________________________________
System.out.println("");
______________________________________
System.out.println("Nama : Roni ______________________________________
Almuzadi"); ______________________________________
______________________________________
System.out.println("NIM : 1814311020");
______________________________________
______________________________________
______________________________________
}
______________________________________
} ______________________________________
______________________________________
______________________________________
______________________________________
______________________________________
______________________________________
______________________________________
Hasil / Output :
MODUL 10
STRING
SOAL 1
Source Code :

package pkg1814311020; ___________________________________


public class Modul10 { ___________________________________
___________________________________
public static void main(String[] args) { ___________________________________
StringBuffer sbuf=new StringBuffer(20); ___________________________________
___________________________________
System.out.println("isi :"+sbuf.toString()); ___________________________________
System.out.println("Kapasitas ___________________________________
:"+sbuf.capacity()); ___________________________________
___________________________________
System.out.println("Panjang :"+sbuf.length()); ___________________________________
___________________________________
___________________________________
sbuf.append("Selamat"); ___________________________________
System.out.println("isi :"+sbuf.toString()); ___________________________________
___________________________________
System.out.println("Kapasitas ___________________________________
:"+sbuf.capacity());
___________________________________
System.out.println("Panjang :"+sbuf.length()); ___________________________________
___________________________________
___________________________________
sbuf.append("Belajar Java"); ___________________________________
___________________________________
System.out.println("isi :"+sbuf.toString());
___________________________________
System.out.println("Kapasitas ___________________________________
:"+sbuf.capacity()); ___________________________________
System.out.println("Panjang :"+sbuf.length()); ___________________________________
___________________________________
System.out.println(""); ___________________________________
System.out.println("Nama : Roni Almuzadi"); ___________________________________
___________________________________
System.out.println("NIM : 1814311020"); ___________________________________
} ___________________________________
___________________________________
___________________________________
} ___________________________________
___________________________________
Hasil / Output :
MODUL 11
METHOD TANPA PARAMETER
SOAL 1
Source Code :

package pkg1814311020; __________________________________


public class Modul11 { __________________________________
__________________________________
public static int jumlah(){ __________________________________
int a = 7, b = 15; __________________________________
__________________________________
return (a + b); __________________________________
} __________________________________
__________________________________
public int kurang(){ __________________________________
int a = 7, b = 15; __________________________________
__________________________________
return (a - b); __________________________________
} __________________________________
__________________________________
public int kali(){ __________________________________
int a = 7, b = 15; __________________________________
__________________________________
return (a * b); __________________________________
} __________________________________
__________________________________
public int bagi(){
__________________________________
int a = 7, b = 15; __________________________________
__________________________________
return (a / b);
__________________________________
} __________________________________
__________________________________
public static void main(String[] args) {
__________________________________
Modul11 obyek = new Modul11(); __________________________________
__________________________________
System.out.println("Hasil pemanggilan method
__________________________________
jumlah");
__________________________________
System.out.println(obyek.jumlah()); __________________________________
System.out.println("Hasil pemanggilan method __________________________________
pengurangan"); __________________________________
__________________________________
System.out.println(obyek.kurang()); __________________________________
System.out.println("Hasil pemanggilan method __________________________________
Perkalian"); __________________________________
__________________________________
System.out.println(obyek.kali()); __________________________________
System.out.println("Hasil pemanggilan method
pembagian");
System.out.println(obyek.bagi());
System.out.println("");
System.out.println("Hasil pemanggilan method _______________________________
pembagian"); _______________________________
System.out.println(obyek.bagi()); _______________________________
_______________________________
System.out.println(""); _______________________________
System.out.println("Nama : Roni Almuzadi"); _______________________________
_______________________________
System.out.println("NIM : 1814311020"); _______________________________
} _______________________________
_______________________________
}
_______________________________
_______________________________
_______________________________
_______________________________

______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________
______________________________________________________________________________________________________

Hasil / Output :
MODUL 12
METHOD DENGAN PARAMETER
SOAL 1
Source Code :

package pkg1814311020; _________________________________


import java.util.Scanner; _________________________________
_________________________________
public class Modul12 { _________________________________
public int banding(int a, int b, int c){ _________________________________
_________________________________
int besar, kecil = 0; _________________________________
if((a<b)&&(a<c))kecil =a; _________________________________
_________________________________
else if ((b<a)&&(b<c))kecil=b; _________________________________
else if ((c<b)&&(c<b))kecil=c; _________________________________
_________________________________
return kecil; _________________________________
} _________________________________
_________________________________
public static void main (String [] args){ _________________________________
Scanner data=new Scanner (System.in); _________________________________
_________________________________
Modul12 bilangan = new Modul12();int a, b, c;
_________________________________
System.out.print("Masukkan bilangan a: "); _________________________________
_________________________________
a=data.nextInt();
_________________________________
System.out.print("Masukkan bilangan b: "); _________________________________
_________________________________
b=data.nextInt();
_________________________________
System.out.print("Masukkan bilangan c: "); _________________________________
_________________________________
c=data.nextInt();
_________________________________
System.out.println("Bilangan terkecilnya adalah _________________________________
"+bilangan.banding(a,b,c)); _________________________________
System.out.println(""); _________________________________
_________________________________
System.out.println("Nama : Roni Almuzadi"); _________________________________
System.out.println("NIM : 1814311020"); _________________________________
_________________________________
} _________________________________
} _________________________________
_________________________________
_________________________________
_________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________
____________________________________________________________________________________________________

Hasil / Output :