Java错误:<identifier>期望无法编译</identifier>

时间:2013-11-23 06:42:09

标签: java compiler-errors

我正在尝试完成一项家庭作业并不断收到两个错误,并且无法弄清楚如何修复它们。这是代码:

import java.util.Scanner;

public class GoughAndreaProg5
{

    public static void main (String[] args)
    {
        Scanner stdIn = new Scanner(System.in);
        System.out.println("Enter a password that meets the following rules: ");
        System.out.println("");
        System.out.println("Is atleast 8 characters long");
        System.out.println("Contains atleast 1 lower letter character");
        System.out.println("Contains atleast 1 upper letter character");
        System.out.println("Contains atleast 1 numeric digit");
        System.out.println("Contains atleast 1 special character from the set: !@#$%^&*");
        System.out.println("Does not contain the word \"and\" or the word \"end\"");
        System.out.println("");
        String myInput = stdIn.nextLine();

        boolean digit = false;
        boolean upperCase = false;
        boolean lowerCase = false;
        for(int x=0; x<myInput.length(); x++)
        {
            if (Character.isDigit(myInput.charAt(x)))
                digit = true;
            if(Character.isUpperCase(myInput.charAt(x)))
                upperCase = true;
            if(Character.isLowerCase(myInput.charA(x)))
                lowerCase = true;
        }
        boolean validLength = true;
        if (myInput.length() < 8)
        {
            System.out.println("Must be at least 8 characters long");
            validLength = false;
        }

        boolean special = false;
            if(myInput.indexOf('!') != -1 | myInput.indexOf('@') != -1 || myInput.indexOf('#') != -1 || myInput.indexOf('$') != -1 || myInput.indexOf('%') != -1 || myInput.indexOf('^') != -1 || myInput.indexOf('&') != -1 || myInput.indexOf('*') != -1)
                    special = true;
            else  //no special character
            {
                System.out.println("Must contain a special character");
            }

            boolean word = false;
            if (myInput.indexOf("and") != -1 || myInput.indexOf("end"));
            {
                word = true;
                System.out.println("Contains the string \"and\" or the word \"end\"");
            }
            if(!digit)
                System.out.println("Must have a numeric digit");
            if(!upperCase)
                System.out.println("Must have an upper case");
            if(!lowerCase)
                System.out.println("Must hava a lower case");

            //output valid or not
            if (validLength && special && !word && upperCase && lowerCase && digit)
                System.out.println("valid");
            else
                System.out.println("not valid");

    } //end main method
    public static void System.out.println(String inStr)
    {
        System.out.println(inStr);
    }  //end of alt string print method

}  //end of class

错误是:

C:\Users\gougha\Documents\Park\Java Class\myJavaPgms\GoughAndreaProg5.java:76: error: '(' expected
public static void System.out.println(String inStr)
                         ^
C:\Users\gougha\Documents\Park\Java Class\myJavaPgms\GoughAndreaProg5.java:76: error:     <identifier> expected
    public static void System.out.println(String inStr)
                                     ^

我已经尝试过所有我能想到的事情。我确定这是一个简单的解决方案,但这对我来说都是如此新鲜,我看不到它。谢谢!

2 个答案:

答案 0 :(得分:2)

您的代码存在多个编译错误

开始

public static void System.out.println(String inStr)

应该是(虽然你不使用它所以我建议只删除这个方法)

public static void println(String inStr)

然后

    if (myInput.indexOf("and") != -1 || myInput.indexOf("end"));

应该是

    if (myInput.indexOf("and") != -1 || myInput.indexOf("end") != -1);

最后

    if(Character.isLowerCase(myInput.charA(x)))

应该是

    if(Character.isLowerCase(myInput.charAt(x)))

答案 1 :(得分:1)

您无需创建此方法public static void System.out.println(inStr)。事实上,语法也是错误的。您只需在创建方法时提供方法名称。不是班级名称。

// Not required at all
public static void System.out.println(String inStr)
{
    System.out.println(inStr);
}

System.out.println()是将值打印到控制台的内置方法。因此,只要您需要在系统的输出控制台上打印内容,只需在main方法中使用System.out.println(inStr)