Topic: 求众位高人点拨,一直想不出应该用什么方法解决问题

  Print this page

1.求众位高人点拨,一直想不出应该用什么方法解决问题 Copy to clipboard
Posted by: abcjavac
Posted on: 2005-12-02 20:43

问题:

写一个类 包含一个方法 public String turnAround (String string),这个方法可以把一串字母顺序颠倒输出 例如:abc -> cba...

后用一个类呼叫一个main方法把三个不同的字串输出到屏幕上

Shuchu {
Shuchu ( ) {

}

public String turnAround (String string){
..........???// 如何实现这个方法的功能, 在API里有现成的类,还是自己写???
}

}

高人帮我! 先谢啦!

2.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: abcjavac
Posted on: 2005-12-02 22:01

public class TurnTest {  
  private String abc;  

  //construktor
  TurnTest (String abc){
  this.abc = abc;
  }
  
  public String turnAround() {
    StringBuffer tur = new StringBuffer();
    tur.toString(); // 这个方法不行可用哪个好呢?
    return abc;
    }  
}

3.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: why
Posted on: 2005-12-02 22:36

abcjavac wrote:
  public String turnAround() {
    StringBuffer tur = new StringBuffer();
    tur.toString(); // 这个方法不行可用哪个好呢?
    return abc;
    }  
}

check StringBuffer API and you'll find
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html#reverse()

4.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: abcjavac
Posted on: 2005-12-02 23:07

谢谢! 看来是应该用reverse方法了.

还有个问题,我的main方法也有问题,我不知道怎么改才好,请给看看

public class TestMain {
  public static void main (String[] args){
    
    TurnTest a = new TurnTest("Baum");
    TurnTest b = new TurnTest("Auto");
    TurnTest c = new TurnTest("Fussball");
    ------------------------------------------------------
    a.turnAround(); //这个地方有问题, 难倒是参数位置不对?
    b.turnAround();
    c.turnAround();
    ------------------------------------------------------
  }
}

5.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: abcjavac
Posted on: 2005-12-02 23:12

另外说说我的问题,我是个初学者,我看书时很多东西都觉得明白了,可到了实际写程序时又会觉得不知所错了,很多结构上的细节,就是吃不准,不知道如何开始尤其是实际的当中,不知是不是别人也有相同的问题,有时候很打击自己的信心的. Sad

6.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: why
Posted on: 2005-12-03 21:03

abcjavac wrote:
还有个问题,我的main方法也有问题,我不知道怎么改才好,请给看看

public class TestMain {
  public static void main (String[] args){
    
    TurnTest a = new TurnTest("Baum");
    TurnTest b = new TurnTest("Auto");
    TurnTest c = new TurnTest("Fussball");
    ------------------------------------------------------
    a.turnAround(); //这个地方有问题, 难倒是参数位置不对?
    b.turnAround();
    c.turnAround();
    ------------------------------------------------------
  }
}

唉--我們怎會知道閣下那TurnTest改成甚麼咚咚?
"这个地方有问题"...有甚麼問題?
閣下這様沒頭沒腦地問,別人怎麼回應?

請好好讀讀 [加贴须知]

7.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-12-04 00:58

I usually don't response the 沒頭沒腦 问题.

Sorry, if the person asking question doesn't want to spend his/her time to tell you what the question is, why should I try to read his/her mind?

Thanks!

8.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: why
Posted on: 2005-12-04 04:33

package net.cjsdn.why;

public class TurnMain {
  public static void main (String[] args){
    TurnTest turnTest = new TurnTest();
    System.out.println(turnTest.turnAround("Baum"));
    System.out.println(turnTest.turnAround("Auto"));
  }
}

class TurnTest {
  public String turnAround(String in) {
    StringBuffer sb = new StringBuffer(in);
    return sb.reverse().toString();
  }
}

9.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: gongshi] Copy to clipboard
Posted by: abcjavac
Posted on: 2005-12-04 14:13

gongshi wrote:
I usually don't response the 沒頭沒腦 问题.

Sorry, if the person asking question doesn't want to spend his/her time to tell you what the question is, why should I try to read his/her mind?

Thanks!


老兄先消消气,我当然花了时间,如果在书里都能看懂了,我也就不会再到这里来问什么问题了,不是吗?
我是确实被困难所困,才来此寻求帮助的,而且也把所有的东西都贴这里了,既然我注册了这个论坛,我也会,尽我所能去帮助其他需要我帮助的人,这就是论坛的职能啊, 哪成想刚来问了两个问题,就给你们二位管事一通奚落, 责备,顺代的还嘲笑了一通我的中文.WHY兄还算回答了问题,可尊驾呢?气势汹汹在中文论坛上用英语加点中文词阻止别人回答我的问题, 您即使就算是 IT 的教授也不至于这么牛吧???谁不是从开始过来的? 最后再问,二位代表的是此论坛的风格吗?还是这就是此坛的规矩-新人都得过这关(先让你们老人挖苦,讽刺,嘲笑一番)??
最后再谢谢WHY兄的回答!

10.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-12-04 17:03

I usually don't response any 沒頭沒腦 问题.

Sorry, if the person who is asking question doesn't want to spend his/her time to tell us what the question is, why should I try to read his/her mind?


This was my preference. This is still my preference now. This will be my preference in the future. I don't represent anybody or any other people's style on the forum.

This is just my choice...
What is wrong with it??????


Thanks!

11.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: why
Posted on: 2005-12-04 17:14

abcjavac wrote:
老兄先消消气,我当然花了时间,如果在书里都能看懂了,我也就不会再到这里来问什么问题了,不是吗?
我是确实被困难所困,才来此寻求帮助的,而且也把所有的东西都贴这里了,既然我注册了这个论坛,我也会,尽我所能去帮助其他需要我帮助的人,这就是论坛的职能啊, 哪成想刚来问了两个问题,就给你们二位管事一通奚落, 责备,顺代的还嘲笑了一通我的中文.WHY兄还算回答了问题,可尊驾呢?气势汹汹在中文论坛上用英语加点中文词阻止别人回答我的问题, 您即使就算是 IT 的教授也不至于这么牛吧???谁不是从开始过来的? 最后再问,二位代表的是此论坛的风格吗?还是这就是此坛的规矩-新人都得过这关(先让你们老人挖苦,讽刺,嘲笑一番)??
最后再谢谢WHY兄的回答!

閣下這麼就算"把所有的东西都贴这里"?開玩笑嗎?
我們怎會知道閣下把那TurnTest改成甚麼咚咚?
"这个地方有问题"...有甚麼問題?


唉--
指出閣下不是之處,不是嘲笑或奚落
請先檢討一下自己有沒有好好地問一個問題
認真一點,試從別人的角度想想吧

12.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: acl2005
Posted on: 2005-12-06 11:24

abcjavac :
我与你有同样的感觉,当你看书的时候觉得还是明白了。但是离开书以后觉得脑袋好象空白了不少啊!不知道从何下手。这样的感觉是不是刚接触的人都有呢,还是少数人有啊!有时很郁闷的

13.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: acl2005] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-12-06 22:47

acl2005 wrote:
abcjavac :
我与你有同样的感觉,当你看书的时候觉得还是明白了。但是离开书以后觉得脑袋好象空白了不少啊!不知道从何下手。这样的感觉是不是刚接触的人都有呢,还是少数人有啊!有时很郁闷的


Hands-on!!!!

Get your hands dirty by writing code to experiment what you are learning!

That is the way to go!
Thanks!

14.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: ftang
Posted on: 2005-12-09 07:07

hehe...I give you guys (abcjavac, acl2005) a good start:

Think about to rewrite the reverse() method of StringBuffer class, no Collection Framework allowed, you can use Array... there are thousands way but we want simplest way....

15.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: javahum
Posted on: 2005-12-11 16:27

自己写了一个,大家补充:

class RoundTest{
public static void main(String []args){
String s="abcdefg";
round(s);

}
public static void round(String s){
StringBuffer sb=new StringBuffer("");
char []c=s.toCharArray();
int m=c.length-1;
for(int i=m;i>=0;i--){
  sb.append(String.valueOf(c[i]));
  
  }  
  System.out.println(sb.toString());
  
  }

}

16.Re:求众位高人点拨,一直想不出应该用什么方法解决问题 [Re: abcjavac] Copy to clipboard
Posted by: hamlet
Posted on: 2005-12-11 22:04

好想法!!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923