Why can't I return a string in Java?

+2 votes
asked May 27 by Rahul Choubey (300 points)

I am defining methods so my Java code can feel a little more like Python. (Please ignore string concatenation with the + as if it is an error, I will solve it!) However, my input function called input() is throwing an error saying 

class, interface, or enum expected

Why is this error being thrown? Not even replacing it with char[] is working! What do I do about it?

My link:

https://onlinegdb.com/By045WnoU

3 Answers

0 votes
answered May 29 by Peter Minarik (4,510 points)
Your methods input() and print() must be within a class (e.g. Main).
0 votes
answered May 29 by Amit Pandey (230 points)
//HOPE THIS WILL HELP U

// YOU SHOULD WRITE ALL YOUR FUNCTION WITH IN THE MAIN CLASS AFTER ALL THEY WILL RUN //PROPERLY AND CALL THE FUNCTIONS IN PUBLIC STATIC VOID MAIN()
0 votes
answered May 29 by osadly (200 points)
Hi,

The issue is not related to returning string from function.

It is because the curly brace bracket '{' is misplaced at the end of the class.  In java, All methods should be included within the class

check the corrected code here

https://www.onlinegdb.com/edit/ryZhV50iI
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...