PERTEMUAN 6
Soal nya
a. Buatlah program untuk menghitung
10 deret bilangan genap dengan hasilnya :
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 = 110
b. Buatlah program untuk menghitung 10 deret bilangan ganjil dengan hasilnya :
1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19 = 100
c. Buatlah program untuk menampilkan deret fibonanci, seperti dibawah ini :
1, 1, 2, 3, 5, 8, 13, 21
d. Buatlah program untuk menampilkan bilangan prima, seperti dibawah ini :
2, 3, 5, 7, 11, 13, 17, 19
A. Program untuk menghitung 10 deret bilangan genap
import java.util.Scanner;
public class genap {
public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Genap antara 2 - 20 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=20){
if((number!=1)&&(number%2==0))
sum= sum + number;
if((number!=1)&&(number%2==0))
System.out.println(number);
number++;
}
System.out.println("-----");
System.out.printf("Jumlah = %d " , sum);
}
}
HASIL OUTPUT :
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 = 110
b. Buatlah program untuk menghitung 10 deret bilangan ganjil dengan hasilnya :
1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19 = 100
c. Buatlah program untuk menampilkan deret fibonanci, seperti dibawah ini :
1, 1, 2, 3, 5, 8, 13, 21
d. Buatlah program untuk menampilkan bilangan prima, seperti dibawah ini :
2, 3, 5, 7, 11, 13, 17, 19
A. Program untuk menghitung 10 deret bilangan genap
import java.util.Scanner;
public class genap {
public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Genap antara 2 - 20 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=20){
if((number!=1)&&(number%2==0))
sum= sum + number;
if((number!=1)&&(number%2==0))
System.out.println(number);
number++;
}
System.out.println("-----");
System.out.printf("Jumlah = %d " , sum);
}
}
HASIL OUTPUT :
B. Program untuk menghitung 10 deret bilangan ganjil
import java.util.Scanner;
public class ganjil {
public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Ganjil antara 1 - 19 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=19){
if((number!=0)&&(number%2==1))
sum= sum + number;
if((number!=0)&&(number%2==1))
System.out.println(number);
number++;
}
System.out.println("-----");
System.out.printf("Jumlah = %d " , sum);
}
}
import java.util.Scanner;
public class ganjil {
public static void main(String[] args) {
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Deret Bilangan Ganjil antara 1 - 19 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=19){
if((number!=0)&&(number%2==1))
sum= sum + number;
if((number!=0)&&(number%2==1))
System.out.println(number);
number++;
}
System.out.println("-----");
System.out.printf("Jumlah = %d " , sum);
}
}
HASIL OUTPUT
:
C.
Buatlah program untuk menampilkan deret fibonanci, seperti dibawah ini :
1,
1, 2, 3, 5, 8, 13, 21
import javax.swing.JOptionPane;
public class Fibonacci
{
public static void main(String[]args)
{
int a = Integer.parseInt(JOptionPane.showInputDialog("Masukkan nilai awal Deret Fibonacci"));
int b = a;
int c = Integer.parseInt(JOptionPane.showInputDialog("Masukkan deret Fibonacci yang Anda Inginkan: "));
int d = c-1;
int e = 1;
System.out.print(a + " ");
while(e <=d)
{
System.out.print(a +" ");
a = a+b;
b = a-b;
e++;
}
}
}
public class Fibonacci
{
public static void main(String[]args)
{
int a = Integer.parseInt(JOptionPane.showInputDialog("Masukkan nilai awal Deret Fibonacci"));
int b = a;
int c = Integer.parseInt(JOptionPane.showInputDialog("Masukkan deret Fibonacci yang Anda Inginkan: "));
int d = c-1;
int e = 1;
System.out.print(a + " ");
while(e <=d)
{
System.out.print(a +" ");
a = a+b;
b = a-b;
e++;
}
}
}
HASIL OUTPUTNYA :
Masukkan nilai awal dan deret
fibonanci nya,,
Ini hasil nya :
D.
Buatlah program untuk menampilkan bilangan prima, seperti dibawah ini :
2,
3, 5, 7, 11, 13, 17, 19
public class BilPrima {
public static void main(String args[]){
int max = 19;
boolean isPrima = false;
for(int i=2; i<=max; i++){
isPrima = true;
for(int j=2; j<i; j++){
if(i % j == 0){
isPrima = false;
break;
}
}
if(isPrima){
System.out.print(i +" ");
}
}
}
}
public static void main(String args[]){
int max = 19;
boolean isPrima = false;
for(int i=2; i<=max; i++){
isPrima = true;
for(int j=2; j<i; j++){
if(i % j == 0){
isPrima = false;
break;
}
}
if(isPrima){
System.out.print(i +" ");
}
}
}
}
PERTEMUAN 7
SOURCE CODE :
import java.util.*;
class TugasPertemuan7
{
public static
void main (String[] args) throws Exception
{
String[]
kode = new String[10];
String[]
jenis = new String[10];
int
i,j;
double
jumlah=0 ,pjk=0, total=0;
int[]
potong = new int[10];
int[]
harga = new int[10];
int[]
jml = new int[10];
Scanner
input = new Scanner(System.in);
System.out.println("|-------------------------------|");
System.out.println("|NAMA :
AZURA|");
System.out.println("|KELAS :
14S01 |");
System.out.println("|-------------------------------|");
System.out.println();
System.out.println("|-------------------------|");
System.out.println("| GEROBAK
FRIED CHICKEN |");
System.out.println("|-------------------------|");
System.out.println("|
Kode | Jenis | Harga |");
System.out.println("|-------|-------|----------|");
System.out.println("| D |
Dada | Rp.2500 |");
System.out.println("| P |
Paha | Rp.2000 |");
System.out.println("| S |
Sayap | Rp.1500 |");
System.out.println("|-------------------------|");
System.out.println();
System.out.print("Banyak
Jenis : ");
j=input.nextInt();
for(i=0;
i<j; i++)
{
System.out.println("\nJenis
Ke - " + (i+1));
System.out.print("Jenis
Potong [D/P/S] : ");
kode[i]=
input.next();
if
("D".equals(kode[i]) || "d".equals(kode[i]))
{
jenis[i]="Dada";
harga[i]=2500;
}
else
if ("P".equals(kode[i]) || "p".equals(kode[i]))
{
jenis[i]="Paha";
harga[i]=2000;
}
else
{
jenis[i]="Sayap";
harga[i]=1500;
}
System.out.print("Banyak
Potong : ");
potong[i]
= input.nextInt();
jml[i]=harga[i]*potong[i];
}
System.out.println("\n\tGEROBAK
FRIED
CHICKEN ");
System.out.println("---------------------------------------------");
System.out.println("No.\tJenis\tHarga\tBanyak\tJumlah");
System.out.println("\tPotong\tSatuan\tBeli\tHarga
");
System.out.println("---------------------------------------------");
for(i=0;i<j;i++)
{
System.out.println(+(i+1)+
"\t" +jenis[i]+ "\t" +harga[i]+ "\t" +potong[i]+
"\t\t" +jml[i]);
jumlah=jumlah+jml[i];
}
System.out.println("---------------------------------------------");
pjk=jumlah*0.1;
total=jumlah+pjk;
System.out.println("\tJumlah
Bayar\t\t\t" +jumlah);
System.out.println("\tPajak
10%\t\t\t\t" +pjk);
System.out.println("\tTotal
Bayar\t\t\t\t" +total);
}
}
HASIL
OUTPUTNYA :
Did you hear there's a 12 word sentence you can speak to your man... that will induce deep emotions of love and instinctual appeal to you deep within his chest?
BalasHapusBecause hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, idolize and guard you with his entire heart...
12 Words Who Fuel A Man's Desire Instinct
This impulse is so built-in to a man's mind that it will drive him to try better than ever before to build your relationship stronger.
Matter-of-fact, fueling this all-powerful impulse is absolutely important to achieving the best possible relationship with your man that the second you send your man a "Secret Signal"...
...You'll instantly notice him open his soul and mind for you in such a way he never experienced before and he'll recognize you as the one and only woman in the galaxy who has ever truly appealed to him.