Error "void is an invalid type for the variable passwordMethod1"

  • Discription: This program check password between 7 to 16
  • characters which contain only characters, numeric digits and underscore
  • and first character*/

import java.util.*;

public class PasswordValidationOne { 
 /**my hints on how to solve this problem
 * the length of the string must not less 7 and must not more than 16 character
 **/
public static void main (String[] args) {
      Scanner scan = new Scanner(System.in);
      System.out.println("Enter a password");
      String password = scan.nextLine();

      public  void  passwordMethod1( password) {
            int lengthPassword = password.length(); // getting the length of the string password
            boolean containsDigit = password.matches("*.\\d*.");
            boolean containsUnderscore = password.contains("_");
            char firstCharacter = password.charAt(0);
            if((lengthPassword >= 7&& lengthPassword<=16)&& (containsDigit == true) && (containsUnderscore == true)&& (firstCharacter >= 'A' && firstCharacter <= 'z') )
                System.out.println("Password Accepted! You can proceed");
            else
                System.out.println("Password not accepted! Retry");
      } //end of method passwordMethod1()

}// end of main method

}//end of the class


The error is correct, if a bit misleading (apparently). This

public  void  passwordMethod1( password) {

is missing the type for password, you wanted

public  void  passwordMethod1(String password) {

Also you cannot declare a method inside another method (move that block outside main).

Error, error, mistake, and blunder mean an act or statement that is not right or true or proper. error is used for failure to follow a model correctly. There was an error in the addition. mistake is used when someone misunderstands something or does not intend to do wrong. Error, in applied mathematics, the difference between a true value and an estimate, or approximation, of that value. In statistics, a common example is the difference between the mean of an entire population and the mean of a sample drawn from that population. In numerical analysis, round-off error


You are missing ( String password) Correct your method parameter

From

public  void  passwordMethod1( password) {
            int lengthPassword = password.length(); // getting the length of the string password
            boolean containsDigit = password.matches("*.\\d*.");
            boolean containsUnderscore = password.contains("_");
            char firstCharacter = password.charAt(0);
            if((lengthPassword >= 7&& lengthPassword<=16)&& (containsDigit == true) && (containsUnderscore == true)&& (firstCharacter >= 'A' && firstCharacter <= 'z') )
                System.out.println("Password Accepted! You can proceed");
            else
                System.out.println("Password not accepted! Retry");
      }

To

public  void  passwordMethod1( String password) {
            int lengthPassword = password.length(); // getting the length of the string password
            boolean containsDigit = password.matches("*.\\d*.");
            boolean containsUnderscore = password.contains("_");
            char firstCharacter = password.charAt(0);
            if((lengthPassword >= 7&& lengthPassword<=16)&& (containsDigit == true) && (containsUnderscore == true)&& (firstCharacter >= 'A' && firstCharacter <= 'z') )
                System.out.println("Password Accepted! You can proceed");
            else
                System.out.println("Password not accepted! Retry");
      }

Lastly add the passwordMethod1 method outside from Main method.

Hope this will help you.

Error, 1.1mass noun The state or condition of being wrong in conduct or judgement. ' goods dispatched to your branch in error'. More example sentences. This article may lack focus or may be about more than one topic. Please help improve this article, possibly by splitting the article and/or by introducing a disambiguation page, or discuss this issue on the talk page.


You have missed the datatype of password in the function declaration.

Try using

public void passwordMethod1(String password) {

Instead of

public void passwordMethod1(password) {

Error, Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. See below� Errors A flaw … would surface like an aching wisdom tooth —James Lee Burke The defects of the mind, like those of the face, grow worse as we grow old —Francois, Due de


You declare the passwordMethod1 inside the main method, that's not valid. The compiler expects a variable there, hence the error message.

Move it outside.

public static void main (String[] args) {
      Scanner scan = new Scanner(System.in);
      System.out.println("Enter a password");
      String password = scan.nextLine();

      passwordMethod1( password);

}// end of main method

public  void  passwordMethod1(String password) {
    int lengthPassword = password.length(); // getting the length of the string password
    boolean containsDigit = password.matches("*.\\d*.");
                boolean containsUnderscore = password.contains("_");
    char firstCharacter = password.charAt(0);
    if((lengthPassword >= 7&& lengthPassword<=16)&& (containsDigit == true) && (containsUnderscore == true)&& (firstCharacter >= 'A' && firstCharacter <= 'z') )
        System.out.println("Password Accepted! You can proceed");
    else
        System.out.println("Password not accepted! Retry");
} //end of method passwordMethod1()

ERROR, NounEdit. error (countable and uncountable, plural errors). (uncountable) The state, quality, or condition of being wrong. quotations ▽. 1913, The Inland printer: . Another word for errors. Find more ways to say errors, along with related words, antonyms and example phrases at Thesaurus.com, the world's most trusted free thesaurus.


Error, Another word for error. Find more ways to say error, along with related words, antonyms and example phrases at Thesaurus.com, the world's most trusted free� When you start Windows by using a normal startup, several applications and services start automatically, and then run in the background. These programs include basic system processes, antivirus software, system utility applications, and other software that has been previously installed.


error, Video shows what error means. The state, quality, or condition of being wrong.. A mistake; an Duration: 0:52 Posted: Apr 12, 2015 Percent error is the difference between an approximate or measured value and an exact or known value. Here is how to calculate percent error.


Error Synonyms, Error Antonyms, error � Related topics: Computers � errorer‧ror /ˈerə $ ˈerər/ ○○○ S3 W2 AWL noun � 1 MISTAKE[countable, uncountable] a mistakeerror in There must be an error� 403 Forbidden errors received when opening links via Microsoft Office programs generate the message Unable to open [url]. Cannot download the information you requested inside the MS Office program.