简体   繁体   English

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

[英]Java error: <identifier> expected unable to compile

I am trying to finish a homework assignment and keep getting two errors and cannot figure out how to fix them. 我正在尝试完成一项家庭作业,并不断遇到两个错误,无法弄清楚如何解决它们。 Here is the code: 这是代码:

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

The errors are: 错误是:

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)
                                     ^

I have tried every thing I can think of. 我已经尝试了所有我能想到的东西。 I'm sure it's an easy fix, but this is all so new to me and I can't see it. 我敢肯定这是一个简单的解决方法,但这对我来说太新了,我看不到。 Thank you! 谢谢!

There are several compile errors with your code 您的代码有几个编译错误

To start 开始

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

should be (though you don't use it so I suggest just remove this method) 应该是(尽管您不使用它,所以我建议您删除此方法)

public static void println(String inStr)

Then 然后

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

should be 应该

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

Finally 最后

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

should be 应该

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

You do not need to create this method public static void System.out.println(inStr) . 您不需要创建此方法public static void System.out.println(inStr) Infact the syntax is also wrong. 实际上语法也是错误的。 You just need to provide a method name when you create it. 您只需在创建方法名称时提供它即可。 Not the class name along with it. 不是类名。

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

System.out.println() is the inbuilt method to print values to the console. System.out.println()是将值打印到控制台的内置方法。 So just use System.out.println(inStr) in your main method, whenever you need to print something on the System's output console. 因此,每当需要在系统的输出控制台上打印某些内容时,只需在主要方法中使用System.out.println(inStr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM