【发布时间】:2011-02-15 04:32:45
【问题描述】:
我被困在这段代码上。
代码应使用 StringBuilder 类来构建输出字符串,方法是将其参数中的非元音字符附加到返回的结果中。它需要使用我创建的辅助方法来识别要删除的元音,该方法是公共布尔 isVowel(char c)。
public String shorthand(String in) 这是我需要帮助的方法。我已经创建了 stringbuilder 但 if 条件不接受 isVowel 方法。
import java.io.*;
import java.util.*;
public class Shorthand
{
public boolean isVowel(char c)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A'|| c == 'E'||c == 'I'|| c == 'O'|| c == 'U')
{
return true;
}
else
{
return false;
}
}
//TODO Complete the shorthand method
public String shorthand(String in) //this is the code I need help with
{
StringBuilder vowel = new StringBuilder();
if (isVowel() == false)
{
vowel.append(in);
}
return vowel.toString();
}
//TODO Complete the run method
public void run() throws IOException
{
String yourLine;
Scanner sc = new Scanner(System.in);
yourLine = sc.nextLine();
while(!yourLine.equals("*"));
{
System.out.println("Enter your line of text");
}
yourLine = sc.nextLine();
}
}
【问题讨论】:
标签: java