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

  • Thread starter Thread starter anyonebutangel
  • Start date Start date
  • Tags Tags
    Code Java String
Click For Summary
To structure Java string code effectively, it is essential to place the code within a static main method. The example provided uses a class named test153, where 'sent' represents the entered sentence, 'l' holds the sentence length, and 'w' temporarily stores each word for printing. This approach aligns with standard practices seen in basic Java examples, such as the "Hello World" program. Utilizing a static main method is crucial for executing the code correctly. Properly organizing code in this manner enhances readability and functionality.
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

  • IMG-20200904-WA0048.jpg
    IMG-20200904-WA0048.jpg
    50.5 KB · Views: 184
Physics news on Phys.org
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 jedishrfu

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K