DoubleGremlin181
DoubleGremlin181

Reputation: 23

In a function prototype it shows an error

it shows cannot find symbol- class string I am writing a program for a report card. This function is to accept names. Pls help

public static string accept_name() {
    String STR[]=new String[40];
    System.out.println("Enter 40 students names");
    for(int a=0;a<=39;a++) {
        STR[a]=br.readLine();
    }
    return (STR);
}

Upvotes: 1

Views: 157

Answers (2)

blank
blank

Reputation: 18180

STR is defined as a String[] but the method signature says it returns a String. You need to change it to

public static String[] accept_name() { ... }

Also, accept_name isn't a good name for a method that return an array of Strings, it doesn't conform to Java method naming standards and doesn't really describe what the method does. STR is also not a well named variable - it should start with lower case letter and describe what it represents something like studentNames. You also don't need the brackets around the variable in the return statement.

Upvotes: 0

BobTheBuilder
BobTheBuilder

Reputation: 19304

Use String not string.

Java types are case sensitive.

Also, you declare return type is String, but you actually returns STR which is of type String[] (array of Strings).

You need to change the return type to String[], or decide which String to return.

Upvotes: 5

Related Questions