You are on page 1of 6

Nama: Alby Fari Husein

Nim: 181011450016

Uts pemograman 1

4.Buatlah Program java Console perulangan:

Source code:
import java.util.Scanner;

public class Menampilkan_bilangan_ganjil_genap {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);


int pilihan, awal, akhir;

System.out.println("PERULANGAN ALBY "

+ "GANJIL & GENAP");

System.out.println("-------------------------------------------------");

System.out.print("Masukan Pilihan [1. Ganjil] | [2. Genap] : "

+ "2 4 6 8 10 12 14 16 ");

pilihan=input.nextInt();

System.out.print("Masukan Nilai Awal : 2 ");

awal=input.nextInt();

System.out.print("Masukan Nilai Akhir : 16 ");

akhir=input.nextInt();

System.out.println("--------------------------- ");

switch (pilihan){

case 1 :

System.out.println("Deret Bilangan Ganjil");

for(int i=awal;i<=akhir;i++){

if (i%2!=0)

System.out.print(i+" ");

break;

case 2 :

System.out.println("Deret Bilangan Genap");

for(int i=awal;i<=akhir;i++){

if (i%2==0)

System.out.print(i+" ");

break;

System.out.println("");
}

3.

Source code:

import java.util.Scanner;

public class switchcase4 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int harga, jumlah, total = 0;

int potongan1, potongan2, potongan3;

System.out.print ("Harga Barang yang harus dibayarkan Alby: Rp 16000");

harga = input.nextInt();

System.out.print ("Jumlah Barang : 16 ");

jumlah = input.nextInt();

total = harga*jumlah;
System.out.println("Total Bayar : Rp 16000 "+ total);

potongan1 = (total -((total*5)/100));

potongan2 = (total - ((total*10)/100));

potongan3 = (total - ((total*15)/100));

if(total >= 200000){

System.out.println("Total Bayar (Diskon 15%) : Rp "+ potongan3);

}else if(total >= 100000 ){

System.out.println("Total Bayar (Diskon 10%) : Rp "+ potongan2);

}else if(total >= 50000){

System.out.println("Total Bayar (Diskon 5%) : Rp "+ potongan1);

if (jumlah >= 50 && total >= 200000) {

System.out.println("Total Bayar (Diskon 5%) : Rp " +(potongan3 -((potongan3*5)/100)));

}else if (jumlah >= 50 && total >= 100000) {

System.out.println("Total Bayar : Rp "+ (potongan2-((potongan2*5)/100)));

}else if (jumlah >= 50 && total >= 50000){

System.out.println("Total Bayar (Diskon 5%) : Rp "+ (potongan1-((potongan1*5)/100)));

}else if (jumlah >= 50){

System.out.println("Total Bayar (Diskon 5%) : Rp "+ (total -((total*5)/100)));}

You might also like