我正在尝试为周一到期的一个项目的计算机编程课程编写代码,而且我对 Java 还是很陌生,但我正在尝试编写一个程序,该程序首先确定用户输入的数字是偶数还是奇数,然后确定该数是否为素数。我不确定我的算法是否正确,所以如果有人对我的算法或其他任何程序有任何更正,请说出来,但我真正的问题是程序拒绝编译。每次我尝试时,它都说它有一个没有 if 问题的 else。这是我的命令框的链接:
http://s1341.photobucket.com/user/Emi_Nightshade/media/Capture_zps45f9a2ea.png.html
这是我的代码:
import java.io.*;
import java.util.*;
public class Lesson9p1_ThuotteEmily
{
public static void main(String args[])
{
Scanner kbReader0=new Scanner(System.in);
System.out.print("\n\nPlease enter an integer. An integer is whole number, and it can be either negative or positive. Please enter your number: ");
long num=kbReader0.nextLong();
if(num%2==0) //if and else with braces
{
System.out.println("Your integer " + num + " is even.");
}
else
{
System.out.println("Your integer " + num + " is odd.");
}
Scanner kbReader1=new Scanner(System.in);
System.out.print("\n\nWould you like to know if your number is prime? Please enter yes or no: ");
String yn=kbReader1.nextLine();
if(yn.equals.IgnoreCase("Yes"))
{
System.out.println("Okay. Give me a moment.");
{
if(num%2==0)
{
System.out.println("Your number isn't prime.");
}
else if(num==2)
{
System.out.println("Your number is 2, which is the only even prime number in existence. Cool, right?");
}
for(int i=3;i*i<=n;i+=2)
{
if(n%1==0)
{
System.out.println("Your number isn't prime.");
}
}
else
{
System.out.println("Your number is prime!");
}
}
}
if(yn.equals.IgnoreCase("No"))
{
System.out.println("Okay.");
}
}
}
如果有人可以帮助我解决这个问题以及我在程序其他地方可能遇到的任何问题,我将不胜感激!谢谢。