/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package bilanganprima;
import java.util.Scanner;
/**
*
* @author
Administrator
*/
public class Main {
/**
* @param args the
command line arguments
*/
public static void
main(String[] args) {
Scanner input =
new Scanner( System.in );
int i, j, min, max, jum=0, total=0;
float rata;
boolean prima;
System.out.print("Masukkan nilai batas bawah:");
min = input.nextInt();
System.out.print("Masukkan nilai batas atas: ");
max = input.nextInt();
while (min > max)
{
System.out.print("\n\nBatas atas harus lebih besar dari
batas bawah.\nMasukkan nilai batas atas: ");
max = input.nextInt();
}
System.out.print("\n");
for (i=min;i<=max;i++)
{
prima=false;
if (i==2)
prima=true;
else
{
for (j=2;j<i;j++)
{
if (i % j==0)
{
prima=false;
break;
}
else
prima=true;
}
}
if (prima) {
System.out.printf("%d\t",i);
jum+=1;
total+=i;
// TODO code
application logic here
}
}
}}
Komentar
Posting Komentar