Hello guys would someone please help me fix my program. I have two classes the one is named GetValues and the other one is SampleReturn. The GetValues class has an error illegal start of expression in the line public static String kuhaName() . The code is below.

GetValues class codes:

import java.util.Scanner;

public class GetValues
{
    private static Scanner inp = new Scanner(System.in);
    private static String z = "";

    public static void wew()
    {
        boolean tryAgain = true;

        System.out.print("Enter name: ");
        String a = inp.nextLine();
        z = a;
        do{
        System.out.print("Enter password: ");
        String pass = inp.nextLine(); 
        if(pass.equals("admin")){
        kuhaName();
        tryAgain = false;
        }
        if (!pass.equals("admin")){
            System.out.print("Try Again!");
            tryAgain = true;
        }
        }while(tryAgain);


    public static String kuhaName()
    {
       return z;
    }
}
}

SampleReturn class code:

public class SampleReturn
{
    public static void main(String[]args)
    {
        GetValues.wew();//First input the name .
        String nameMo = GetValues.kuhaName();//Retrieve the name
        System.out.print("Your name is: " +nameMo);//Display the name
    }
}

Recommended Answers

All 3 Replies

Missing the final } on the previous method.

Oh yes right. I also found my second method is inside my first method. Thanks for the help anyway.

The "Illegal Start of Expression" compiler screech is almost always caused by a curly-brace leak.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.