# y

user_7597543
java
2 years ago
2.0 kB
1
Indexable
Never
```import java.util.Scanner;
public class TugasPersonalMita {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char choice;
do{
System.out.println("Belajar Deret Aritmatika, Geometri dan Menghitung Faktorial");
System.out.println("Masukkan Banyak Angka Yang Ingin Dicetak [2-10]: ");
int banyakangka = scan.nextInt();
System.out.println("Masukkan Beda Masing-Masing Angka [2-9]: ");
int bedaangka = scan.nextInt();

String deretaritmatika = "Deret Aritmatika: ";
String deretgeometri = "Deret Geometri: ";
String faktorial = "Faktorial Dari " + banyakangka + ":";

System.out.print(deretaritmatika + "\n");
for (int i = 1; i <= banyakangka * bedaangka; i = i +
bedaangka) {
System.out.print(i + " ");
}

System.out.print("\n" + deretgeometri + "\n");
int a = 1, total = 0;
for(int i = 1; i <= banyakangka; i++){
System.out.print(a + total);
a = a * 2;
if (i<banyakangka){
System.out.print(" ");
} else{
System.out.print("");
}
}

System.out.print("\n" + faktorial + "\n");
for (int i = banyakangka;
i >= 1; i--) {
System.out.print(i + " ");
}
System.out.println(" = " + faktoriall (banyakangka));

System.out.println("Apakah Anda Ingin Mengulang? [Y/T]: ");
choice = scan.next().charAt(0);
}
while (choice == 'y' || choice == 'Y') ;
scan.close();
}
public static int faktoriall(int n){
if (n==1){
return 1;
}else{
return n * faktoriall(n - 1);
}
}
}```