標題:
406-遞迴字串計算
[打印本頁]
作者:
許承鴻
時間:
2018-8-14 18:15
標題:
406-遞迴字串計算
import java.util.Scanner;
public class JPD04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
...
}
public static int countA(String str) {
...
}
}
複製代碼
作者:
張閎鈞
時間:
2018-8-14 20:11
package hi87;
import java.util.Scanner;
public class hi788 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int b = 0;
System.out.print("Input a string");
String a=keyboard.next();
System.out.print(a+" has "+f(a)+" As");
}
static int f(String str) {
if(str.equals (""))
{
return 0;
}
else if(str.substring(0,1).equals ("A"))
{
return 1+f(str.substring(1));
}
else
{
return f(str.substring(1));
}
}
}
複製代碼
作者:
巫沛庭
時間:
2018-8-14 20:26
package text;
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
System.out.print("Input a string: ");
String num=keyboard.nextLine();
System.out.print(num+"has"+countA(num)+"As");
}
public static int countA(String str) {
if(str.equals(""))
{
return 0;
}
else if(str.substring(0,1).equals("A"))
{
return 1+countA(str.substring(1));
}
else
{
return countA(str.substring(1));
}
}
}
複製代碼
作者:
巫晉宇
時間:
2018-8-18 15:11
package wwe;
import java.util.Scanner;
public class JPA04 {
static Scanner k = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
System.out.println("Input the string: ");
String n=k.next();
System.out.println(n+" has "+countA(n)+" aaaAs");
System.out.println("Input the string: ");
n=k.next();
System.out.println(n+" has "+countA(n)+" As");
}
public static int countA(String n)
{
if(n.equals(""))
{
return 0;
}
else if(n.substring(0,1).equals("A"))
{
return 1+countA(n.substring(1));
}
else
{
return countA(n.substring(1));
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2