English 中文(简体)
帮助寻找扼杀时间的过程方法
原标题:help with process method to find the length of a string
  • 时间:2011-08-17 11:12:45
  •  标签:
  • java

这是我的歌曲。

/* 
 *
 */

public class SongApp{
  public static void main(String[] args){
  Song song1 = new Song();
  song1.setsongLine("While my guitar gently weeps.");
  song1.display();
  song1.process();
  Song song2 = new Song();
  song2.setsongLine("Let it be");
  song2.display();
  }
}

这是我的支持者。

/* 
 *
 */

public class Song{
  // data field declaration
  private String songLine;


  /*sets the value of the data field songLine to input parameter value*/
  public void setsongLine(String songLine){      
    this.songLine = songLine;   
  } //end method  

 /*returns the value of the data field songLine */
 public String getsongLine(){      
    return songLine;      
 } //end method


  //method called process
  public String process(){
    int stringLength = songLine.length();
  }
  /*displays formatted songLine information to the console window */  
  public void display(){     
   System.out.println(songLine); 
   System.out.println("Length is :" + process());
  }
}

因此,我的问题正在采用程序方法,即需要印刷歌曲的长度,然后产生例如Length的产出:9,但我的处理方法似乎一直努力工作。

问题回答

您需要从<代码>程序()方法中回归<代码>。

public static void main(String[] args){
    ...
    System.out.println(song1.process());
    ...
}
public String process(){
    return "Length is " + songLine.length();
}

......或您可将其编成<条码> 删除:

public void process(){
    System.out.println("Length is " + songLine.length());
}

你们是否试图回到这一进程的方法中?

Your process method is basically a noop. Either return the results or store it in a member variable.

如果你希望从程序上恢复一段时期的话:

public Integer process() {
    return songLine.length();
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签