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

In summary, the conversation is about using a static main method to contain code in a Java program. The length of the sentence and variable for storing words are also mentioned.
  • #1
anyonebutangel
40
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: 115
Physics news on Phys.org
  • #2
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.
 
  • #3
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

1. What is a Java string code?

A Java string code is a sequence of characters used to represent text in a Java program. It is a data type that stores a series of characters, such as letters, numbers, and symbols. It is commonly used for storing and manipulating text-based data.

2. How do I write a Java string code?

To write a Java string code, you can use the String class and its methods. For example, you can create a string variable by using the keyword "String" followed by the variable name and an equal sign, and then assigning a value within double quotes. You can also use various methods to manipulate and modify the string as needed.

3. What is the purpose of using a Java string code?

The purpose of using a Java string code is to handle and manipulate text-based data in a Java program. It allows you to store and display text, as well as perform operations such as concatenation, searching, and replacing. It is an essential data type for creating user interfaces, processing user input, and working with text files.

4. Can you provide an example of a Java string code?

Yes, here is an example of a Java string code that declares a string variable named "name" and assigns it the value "John":
String name = "John";
This code creates a string variable named "name" and assigns it the value "John" using the String class.

5. How can I get help with my Java string code?

You can get help with your Java string code by consulting online resources, such as tutorials, forums, and documentation. You can also ask for assistance from fellow programmers or seek help from a professional Java developer. Additionally, you can use debugging tools to identify and fix errors in your code.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
949
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Back
Top