Anda di halaman 1dari 6

# 1.

package Praktikum3;
import java.util.ArrayList;
import java.util.Scanner;
public class

Array1 {

int a = 0;
int b = 0;
int n = 0;

## Scanner a_input = new Scanner(System.in);

Scanner b_input = new Scanner(System.in);
Scanner n_input = new Scanner(System.in);

## System.out.println("Program Pencari Koeffiesien binomial:");

System.out.println("(a+b)^n");

System.out.print("a: ");
a = a_input.nextInt();

System.out.print("b: ");
b = b_input.nextInt();

System.out.print("n: ");
n = n_input.nextInt();

System.out.print(calculateBinomialTheorem(a, b, n));

a_input.close();
b_input.close();
n_input.close();
}

## private static int calculateBinomialTheorem(int a, int b, int n) {

int result = 0;
int koefisien = 0;

int product = 0;

## koefisien = factorial(n) / (factorial(i) * factorial(n - i));

product = (int) (koefisien*Math.pow(a, n - i)*Math.pow(b, i));

}

for(int c : products) {
result += c;
}
return result;
}

## private static int factorial(int num) {

int factorial = 1;

if(num > 0) {
for ( int c = 1 ; c <= num ; c++ )
factorial = factorial*c;
} else {
return 1;
}

return factorial;
}
}

2. package Praktikum3;
import java.util.Scanner;
public class Array2 {
public static void main(String[] args) {
Scanner show = new Scanner(System.in);
System.out.print("Masukan Jumlah Deret Fibonacci : ");
int n = show.nextInt();
System.out.println("Masukkan Angka Pertama : ");
int X = show.nextInt();
System.out.println("Masukkan Angka Kedua : ");
int Y = show.nextInt();
long fib[] = new long[n];
fib[0] = X;
fib[1] = Y;

## for(int i = 2; i < n; i++) {

fib[i] = fib[i-1] + fib[i-2];
}
for (int i = 0; i < n; i++) {
System.out.print(fib[i] + " ");
}
show.close();
}

3. package Praktikum3;
import java.util.Scanner;
public class Array3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

## System.out.print("Masukkan Angka Pertama = ");

int a = input.nextInt();
System.out.print("Masukkan Angka Kedua = ");
int b = input.nextInt();
System.out.print("Masukkan Angka Ketiga = ");
int c = input.nextInt();
System.out.print("Masukkan Angka Keempat = ");
int d = input.nextInt();
System.out.print("Masukkan Angka kelima = ");
int e = input.nextInt();
input.close();
int[] DaftarArray = new int[]{a, b, c, d, e, };
int Terkecil = DaftarArray[0];
int Terbesar = DaftarArray[0];
for(int i=1; i< DaftarArray.length; i++){
if(DaftarArray[i] > Terbesar){
Terbesar = DaftarArray[i];
}
else if (DaftarArray[i] < Terkecil){
Terkecil = DaftarArray[i];
}
}
System.out.println("Nilai Terbesar : " + Terbesar);
System.out.println("Nilai Terkecil : " + Terkecil);
}
}

4. package Praktikum3;
import java.util.Scanner;
public class Array4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner masukan = new Scanner(System.in);
long bilangan;
int sisa;
int [ ] array = new int [100];
boolean loop = true;
int i = 0;
+");

## System.out.println("+++Konversi Bilangan Desimal ke Bilangan Biner++

System.out.print ("Bilangan Desimal : ");
bilangan=masukan.nextLong();//Bil desimal
System.out.print("Nilai Biner = ");
while (loop == true){//Bilangan sisa (modulus)
sisa = (int) (bilangan % 8);
bilangan = bilangan / 8;
array [i] = sisa;
i++;
if (bilangan<8){
loop=false;

## array [i] = (int) bilangan;

}
for (int a=i; a>=0; a--){//Bilangan sisa dengan konversi dari oktal ke
biner

if (array [a]==0){
if (array [a]==0 && a==i)
System.out.print("");
else
System.out.print("000");
}
if (array [a]==1){
if (array [a]==1 && a==i)
System.out.print("1");
else
System.out.print("001");
}
if (array [a]==2){
if (array [a]==2 && a==i)
System.out.print("10");
else
System.out.print("010");
}
if (array [a]==3){
if (array [a]==3 && a==i)
System.out.print("11");
else
System.out.print("011");
}
if (array [a]==4)
System.out.print("100");
if (array [a]==5)
System.out.print("101");
if (array [a]==6)
System.out.print("110");
if (array [a]==7)
System.out.print("111");
}
}
masukan.close();

## 1tes. package Praktikum3;

import java.util.Scanner;
public class TesArray1 {
public static void main(String[] args) {
// TODO Auto-generated method stub

## Scanner X=new Scanner (System.in);

System.out.println("Program Pencari Koeffiesien binomial:");
System.out.println("(a+b)^n");
System.out.print("Masukkan nilai a = ");
int a = X.nextInt();
System.out.print("Masukkan nilai b = ");
int b = X.nextInt();
System.out.print("Masukkan nilai n = ");
int n = X.nextInt();
X.close();
int R[]={a,b,n};
int Hasil =(int) Math.pow((R[0]+R[1]),R[2]);
System.out.println("Hasil = "+Hasil);
}
}

## 4tes. package Praktikum3;

import java.util.Scanner;
public class TesArray1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner X=new Scanner (System.in);
System.out.println("Program Pencari Koeffiesien binomial:");
System.out.println("(a+b)^n");
System.out.print("Masukkan nilai a = ");
int a = X.nextInt();
System.out.print("Masukkan nilai b = ");
int b = X.nextInt();
System.out.print("Masukkan nilai n = ");
int n = X.nextInt();
X.close();
int R[]={a,b,n};
int Hasil =(int) Math.pow((R[0]+R[1]),R[2]);
System.out.println("Hasil = "+Hasil);
}
}