publicstaticvoidmain(String[]args){c=newConsole();intinteger=0;booleanisPrime;charconti;do{c.println("Pleaseenterinaninteger.");c.println("Thisprogramwilltestifthisintege...
public static void main (String[] args)
{
c = new Console ();
int integer = 0;
boolean isPrime;
char conti;
do
{
c.println ("Please enter in an integer.");
c.println ("This program will test if this integer is a prime number.");
integer = c.readInt ();
isPrime (integer);
c.println ();
c.println ("Do you wish to continue? Y/N?");
conti = c.readChar ();
}
while (conti == 'y' | conti == 'Y');
} // main method
public static boolean isPrime (int number)
{
int count = 2;
for (count = 2 ; count <= number ; count++)
{
if (number % count == 0)
return false;
else
return true;
}
}
}
为什么它说我最后的布尔值不匹配..?
对不起哈.. 因为是老师留的英文的题要我们做.. 实在不会..
T.T 多谢好心人帮忙..
Write an application that calls on a method:
boolean isPrime((int n))
that will return a true or false whether n is prime or not. A prime number is a number that is divisible only by 1 and itself. For example, 2, 3, 5, and 7 are prime, but 4, 6, 8 and 9 are not. We only need to test for factors of n that are less than or equal to the square root of n.
Allow the user to repeat the program over.
程序终于可以执行拉, 可是无论输入什么值, 出来的都说是质数..为什么那..?
展开