class ex3
{
public static void main(String args[])
{
java.util.Scanner sc=new java.util.Scanner(System.in);
int factor=0,total=0,a,b,divide;
while(true)
{
System.out.println("找介於a和b的質數(正整數),請輸入:");
System.out.print("a=");
a=sc.nextInt();
System.out.print("b=");
b=sc.nextInt();
if(a>0&&b>0)
{
break;
}
System.out.println("不能輸入負數!請重來!");
}
for(int i=a;i<=b;i++)
{
for(int j=1;j<=i;j++)
{
if((i%j)==0)
{
factor++;
}
}
if(factor==2)
{
total++;
}
factor=0;
}
System.out.println("介於a和b的質數總共有"+total+"個");
}
}