Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why can't I return a string in Java?

+2 votes
asked May 27, 2020 by Rahul Choubey (550 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, 2020 by Peter Minarik (84,720 points)
Your methods input() and print() must be within a class (e.g. Main).
0 votes
answered May 29, 2020 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, 2020 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.
...