Menghitung Nilai Factorial
Menghitung Nilai Factorial
Menghitung Nilai Factorial
2. package tugas1;
3. import java.util.Scanner;
4. public class No01 {
5. public static void main(String[] args) {
6. //Menghitung nilai faktorial suatu bilangan (n)
14. if (i<n) {
15. System.out.print( i +"x") ; }
16. else {
17. System.out.println( i+ " ");
18. System.out.print( n+ "!= " + fak);
}
}
}
}
19. Menghitung Nilai Fibonacci
package tugas1;
import java.util.Scanner;
package tugas1;
import java.util.Scanner;
public class No2 { // Menghitung nilai fibonacci
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int fib1=0, fib2=1, fib3, n;
System.out.print("Mencetak fibonacci hingga elemen ke = ");
n = sc.nextInt();
fib3 = fib1+fib2;
fib1 = fib2;
fib2 = fib3;
i = i+1;
if (i==2)
System.out.println("fib3 = " + fib3);
else {}
System.out.println("fib" + i + " = "+fib3);
}
}
}
3. Menentukan suatu bilangan prima atau tidak
package tugas1;
import java.util.Scanner;
public class No3 { // menentukan suatu bilangan prima atau tidak
public static void main(String[] args) {
// TODO Auto-generated method stub
String hasil = "Bilangan Prima";
int bil, bagi ;
Scanner sc= new Scanner(System.in);
System.out.print("Bil = ");
bil = sc.nextInt();
package tugas1;
import java.util.Scanner;
public class No04 { // Menghitung banyaknya pecahan mata uang untuk penggajian
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int gaji, seratusribuan, limapuluhribuan, duapuluhribuan, sepuluhribuan,
limaribuan, duaribuan, seribuan, limaratusan,seratusan;
System.out.print("gaji =");
gaji = sc.nextInt();
package tugas1;
import java.util.Scanner;
public class No05 { // Mengkonversi mata uang rupiah
public static void main(String[] args) {
System.out.print("Rp");
rp = in.nextInt();
rp_to_usd = rp/usd;
rp_to_ugd = rp/ugd;
rp_to_aud = rp/aud;