Perulangan Deret Angka

Untuk membuat deret angka dengan urutan tertentu dengan menggunakan java sebagai contoh untuk membuat deret dari:

1. 1, 2, 4, 8, …
2. 100, 3, 95, 6, 90, 9, …
3. Angka antara 0 s/d 100

public class DeretAngka {

    public void deret3() {
        for (int i = 0; i <= 20; i++) {
            int c = (int) Math.pow(2, i);
            System.out.print(c + ",");
        }
    }

    public void deret1003() {
        int s = 105;
        for (int i = 0; i < 10; i++) {
            if (i == 0) {
            } else {
                System.out.print(i * 3 + ",");
            }
            s = s - 5;
            System.out.print(s + ",");

        }
    }

    public void deret100() {

        for (int i = 0; i <= 100; i++) {
            if (i == 0 || i == 100) {
            } else {
                System.out.println(i + ",");
            }
        }
    }

    public static void main(String[] args) {
        DeretAngka deret = new DeretAngka();
        deret.deret3();
        deret.deret1003();
        deret.deret100();

    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s