Berikut adalah Source Code untuk menampilkan bilangan prima antara 1 hingga 100 menggunakan java.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bil_prima;
/**
 *
 * @author mwpripanggalih
 */
public class Bil_prima {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         char tanda[] = new char[101];
        for (int i = 2; i <= 100; i++) {
            if (tanda[i] != '*') {
                System.out.print(i + " ");
                for (int j = i * 2; j <= 100; j += i) {
                    tanda[j] = '*';
                }
            }
        }
    }
}
Next
« Prev Post
« Prev Post
Previous
Next Post »
Next Post »
Langganan:
Posting Komentar (Atom)
EmoticonEmoticon