当前位置: 代码迷 >> Java相关 >> 加分答题
  详细解决方案

加分答题

热度:319   发布时间:2004-09-15 20:34:00.0
加分答题

OK刚刚我看C那里有一个叫有奖答题的东东。现在我也写个题目。第一个答对的有50分的加分(版主除外)。

In case you guys want to get used to Java English, i will write the whole thing in English

(In face, it is also a bit hard for me to translate all the Java word into Chinese,:P, sorry guys)

Ok, I promise the question i write (and maybe future??) will be nice and simple so that most of people here will actually have a chance to do this (and at least think).

=====================================================================

Here comes the Question.

Write a class, called Reverse.java, which takes an command line argument, and print that String back to the screen but in its reverse order.There are lots of ways to do the simple task!!!

For example:

C:\javaPro\java Reverse apple

elppa <<<<<this is the output

C:\javaPro\java Reverse a

a <<<<<<this is the output

C:\javaPro\java Reverse "apple tree"

eert elppa <<<<<<this is the output

(you can assume that the user will enter at lease one character so that no Exception will be ever thrown...

Extension: If no loop is allowed in this question, what will you do it? (if you could do without any loops in the class, +60 :-) )

Have Fun!!!

=====================================================================

Important: When you reply, do not just write a post and reply, please upload an attachment as a .java file (in this case Reverse.java), to do this, it will make much simpler when you are writing the program and it is also easy for others (including me) to check if your program works or not (since we can run it straightaway without copy and paste).

If you are the 1st, and 50 will be added!

[此贴子已经被作者于2004-09-15 21:04:05编辑过]

搜索更多相关的解决方案: 答题  

----------------解决方案--------------------------------------------------------

Here is my programme for this question, and i accomplished it without any loop.

What should you do now , Anstey ? ^_^

Well done! A tuff approch using recursion, and in fact this is what i expect by saying "using no loop"

As I promise, 60 will be added.

Thanks.

--------by Anstey

[此贴子已经被Anstey于2004-09-16 15:34:07编辑过]


----------------解决方案--------------------------------------------------------

虽然已经有第一个60, 因为只有一个回复,所以50仍然有效,so keep doing it.....!!!

可能问题简单了一点。。。呵呵,ANYWAY。。

下次会更难一点。。。。呵呵 maybe....


----------------解决方案--------------------------------------------------------

50 is also available? But i think it's too .....if we accoplish it with a loop. Since Anstey has claimed that such a programme with a loop can also derive 50, i will have a try. ^_^


----------------解决方案--------------------------------------------------------

No, I am sorry, I have already added 60 to you....

Dont be too...... :


----------------解决方案--------------------------------------------------------
Such a sequence is in my expect........................
----------------解决方案--------------------------------------------------------
Anstey, I think it's better that you let your such an information about adding scores through design programmes you assigned be known by many people, otherwise it's very likely that i am the only one who engages in your topic.
----------------解决方案--------------------------------------------------------
Can you say Chinese? I don`t speak English!!!
----------------解决方案--------------------------------------------------------

import javax.swing.JOptionPane;

class Reverse{ public static void main(String args[]){ String output ="" ; int i , j , k ; String input = JOptionPane.showInputDialog("Please Enter String") ; if (input.length() <= 60){ for ( i = input.length() -1 ; i > 0 ; i--) output+= input.charAt( i ); } else for( i = input.length() -1 ; i >0 ; i-- ) for ( i = input.length(), j= 0 ; j<i/60 ; j++){ output+= input.charAt( i ); output+= "\n" ; } // System.out.println("The Reversion of the String is : " +output) ; JOptionPane.showMessageDialog( null , output, "Reverse Program", JOptionPane.PLAIN_MESSAGE); System.exit(0); } }

我是一个新手,编了一段这样的程序,可是不能实现原题的目的(字符串的最后一个字母总是显示不出来),请各位高手指点啊


----------------解决方案--------------------------------------------------------
我的英语不太好,看不懂.
----------------解决方案--------------------------------------------------------
  相关解决方案