Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
4
Indexable
Never
import java.util.Scanner;

public class TP2 {

	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 beda = 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 * beda; i = i +
	            beda) {
	       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(" = " + Faktorial (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 Faktorial(int n){
	        if (n==1){
	            return 1;
	        }else{
	            return n * Faktorial (n - 1);
	        }
	    }
	}