У меня проблемы с определением некоторых ошибок компилятора, таких как недопустимое начало выражения в моих операторах if и else и else без if.
import java.util.Scanner;
public class A3Q1
{
public static void main(String[]args)
{
System.out.println("Perfect square identifier (Enter -1 to quit program)");
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number: ");
String squareNumStr = sc.nextLine(); //taking user input
int squareNum = Integer.parseInt(squareNumStr); // taking string turning it into int
boolean exitCommand = true;
while(exitCommand)
{
if(squareNum >= 0) // will run method if int is a positive
{
perfectSquareIdentifier();
if(return == true) // using boolean return to print
{
System.out.println(squareNum + " is a perfect square.");
}
else if(return == false)
{
System.out.println(squareNum + " is not a perfect square");
}
}
else if(squareNum == -1)
{
exitCommand = false;
System.out.println();
}
}
System.ou.println("End of processing...");
}
public static boolean perfectSquareIdentifier(int squareNum)
{
int squareRoot = Math.sqrt(squareNum); //taking square root of user input
if (squareRoot*squareRoot == squareNum) // testing if the root provided is a root or a number with remainders
{
return true;
}
else
{
return false;
}
}
}