Last Updated on 13 years by Hafizh Herdi
Oke sebenarnya ini adalah salah program jadul sederhana buatan saya. Dimana fungsi utamanya adalah untuk mengecek jumlah bilangan prima pada batas-batas tertentu. Misalnya kita ingin mengecek ada berapa bilangan prima di antara angka 1 sampai 10, maka program ini akan mengeluarkan ouput berupa 4, karena pada angka 1 sampai sepuluh ada 4 bilangan prima. Yaitu 2, 3, 5 dan 7.
Oiya, program ini aslinya saya buat untuk teman saya. haha Dibikin dulu waktu saya sedang seneng-senengnya pake Linux. Kalo nggak salah ini dibikin menggunakan Geany IDE di Linux Ubuntu.
-
/*
-
* cekprima.java
-
*
-
* Copyright 2011 Hafizh Herdi Naufal <twohnuvo@gmail.com>
-
* http://twitter.com/twoh | http://twoh.co
-
* This program is free software; you can redistribute it and/or modify
-
* it under the terms of the GNU General Public License as published by
-
* the Free Software Foundation; either version 2 of the License, or
-
* (at your option) any later version.
-
*
-
* This program is distributed in the hope that it will be useful,
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
* GNU General Public License for more details.
-
*
-
* You should have received a copy of the GNU General Public License
-
* along with this program; if not, write to the Free Software
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-
* MA 02110-1301, USA.
-
*/
-
import java.util.Scanner;
-
class cekprima
-
{
-
public static boolean cekpr(int i)
-
{
-
boolean k = true;
-
int j;
-
for(j = 2; j <= i; j++)
-
{
-
if(i % j == 0 && j != i)
-
{
-
k = false;
-
}
-
}
-
return k;
-
}
-
{
-
int awal, akhir;
-
awal = s.nextInt();
-
akhir = s.nextInt();
-
boolean pr = false;
-
for(int i = awal; i <= akhir; i++)
-
{
-
pr = cekpr(i);
-
if (pr == true)
-
{
-
if(i != 1)
-
{
-
}
-
}
-
}
-
}
-
}
Enjoy!
Inilah program pertama yang aku buat di bahasa Java~ Hope it will do good for me.