我需要帮助我的代码,它由两个方法组成。我想使用我的方法"obify"和"normalizeText"。目标是在每个元音 i 用户输入的文本之前放置 OB。 我知道当我把这个:
String c = b.replaceAll("(?i)([aeiou])", "OB$1");
System.out.println(c);
在规范化测试方法中,它可以工作。但是我想制作一个名为obify()的方法,该方法无需将其放入normalizeText()中即可执行此操作。
这是我尝试使用的代码。
import java.util.Scanner;
public class Text {
public static void main( String[] args){
normalizeText();
obify();
}
static void normalizeText(){
String a;
Scanner scan = new Scanner(System.in);
System.out.print("Write your String");
a = scan.nextLine();
System.out.print("String is: " + a);
a = a.replaceAll("\W", "");
a = a.toUpperCase();
String b = a.replaceAll("\s", "");
/* then I just return the text that the user input
but now without the spaces or punctuations. The text will also
be in all caps
*/
System.out.println("n output String is:" + b);
/*
String c = b.replaceAll("(?i)([aeiou])", "OB$1");
System.out.println(c);
*/
}
static void obify(){
String c = b.replaceAll("(?i)([aeiou])", "OB$1");
System.out.println(c);
}
}
谢谢!
你将不得不使用一些返回类型。下面是代码的外观示例:
public static void main( String[] args){
String textToDoStuffTo = "Change this text";
//you can do it like this
textToDoStuffTo = normalizeText(textToDoStuffTo);
textToDoStuffTo = obify(textToDoStuffTo);
//or you can combine them like this
normalizeText(obify(textToDoStuffTo));
}
static String normalizeText(String text){
//changes the text
return text;
}
static String obify(String text){
//changes the text
return text;
}