Kamis, 30 Juli 2009

Bilangan Prima

Hua mantab nih dapet pertanyaan simple tapi susah juga,
cuma disuruh nampilin bilangan prima cuma mesti pake bahasa jawa..

import java.util.*;

public class prak

{
public statis void main (string[]args);
Scanner input = new scanner(System.in);
tes obj1= new tes();
System.out.print("banyak = ");
int x = input.nextInt();
obj1.prima(x);
System.out.println();
}

class tes
{

void prima(int x)
{
System.out.print("hasil = ");
for (int i=1;i=x;i++)
{ int p= 0;
for (int j=1;j=x;j++)
{
if (i%j==0) then
{ p=p+1};else {p=p};
}
if (p==2) then
{ System.out.print(i+" ");
int jml=jml+i;
x=x+1;
} else
{
x=x;
}
System.out.print("hasil=%d",jml);
}



bener gak y?

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda