How to Structure Java String Code in a Static Main Method?

2 replies · 2K views · last reply
anyonebutangel
Messages
40
Reaction score
5
Homework Statement
I want to write a program in java that takes a sentence as an input and displays each word separately in a new line .I came up with this .But the compiler is displaying an error and i can't make out where i made a mistake.
Relevant Equations
no idea what equations
it's written in Java and compiled with JDK1.5
here the class name is test153 sent is the sentence entered l is the length of the sentence w is the variable storing each word temporarily before printing.
 
Attachments
  • Screenshot of a Windows Command Prompt showing javac compile errors for test153.java, beside a Notepad window containing the Java source code of class test153 that splits a sentence into words.
    IMG-20200904-WA0048.jpg
    50.5 KB · Views: 224
Look for a hello world example in java and you’ll see they use a static main method To contain their code.

Basically you need to place your code in a static main method.
 
jedishrfu said:
Look for a hello world example in java and you’ll see they use a static main method To contain their code.

Basically you need to place your code in a static main method.
yeah.done thanks for help.
 
  • Like
Likes   Reactions: jedishrfu