標題:
408-遞迴字串反向
[打印本頁]
作者:
許承鴻
時間:
2018-8-21 18:19
標題:
408-遞迴字串反向
import java.util.Scanner;
public class JPD04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
String s, c;
System.out.print("Input a string: ");
s = keyboard.nextLine();
System.out.printf("%s\n", reverse(s));
System.out.print("Input a string: ");
s = keyboard.nextLine();
System.out.printf("%s\n", reverse(s));
}
...
}
複製代碼
作者:
張閎鈞
時間:
2018-8-21 19:04
package hi87;
import java.util.Scanner;
public class hi78 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
String s, c;
System.out.print("Input a string: ");
s = keyboard.nextLine();
System.out.printf("%s\n", reserve(s));
}
static String reserve( String str)
{
if(str.equals(""))
{
return "";
}
else{
return reserve(str.substring(1))+str.substring(0,1);
}
}
}
複製代碼
作者:
巫沛庭
時間:
2018-8-21 19:07
package text;
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
String s, c;
System.out.print("Input a string: ");
s = keyboard.nextLine();
System.out.printf("%s\n", reverse(s));
}
static String reverse(String n)
{
if(n.equals(""))
{
return "";
}
else{
return reverse(n.substring(1))+n.substring(0,1);
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2