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

  • Context: Comp Sci 
  • Thread starter Thread starter anyonebutangel
  • Start date Start date
  • Tags Tags
    Code Java String
Click For Summary
SUMMARY

The discussion focuses on structuring Java code within a static main method, specifically using a class named "test153". Participants emphasize the importance of placing code inside the static main method, as demonstrated in typical "Hello World" examples in Java. Key variables mentioned include "sent" for the input sentence, "l" for the sentence length, and "w" for temporarily storing each word before printing. This structure is essential for executing Java applications effectively.

PREREQUISITES
  • Understanding of Java programming language
  • Familiarity with static methods in Java
  • Basic knowledge of variable declaration and usage
  • Experience with Java class structure
NEXT STEPS
  • Review Java static method syntax and usage
  • Explore Java variable types and their scope
  • Study examples of Java class structures
  • Practice writing and executing simple Java applications
USEFUL FOR

Java developers, programming students, and anyone looking to understand the fundamentals of structuring Java applications using static methods.

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: 196
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   Reactions: jedishrfu

Similar threads

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