我制作了以下课程StringToolsNS123
,其中包含许多方法
public class StringToolsNS123 {
private String str;
public StringToolsNS123(String s) {
str = s;
}
public String getString() {
return str;
}
public void setString(String s) {
str = s;
}
public String toString() {
return str;
}
public int countWord() {
String st = " " + str;
char curr, prev ;
int count =0;
for (int i = 0; i <= st.length()-2; i++)
{
prev = st.charAt(i);
curr = st.charAt(i+1);
if (Character.isLetter(prev) == false && Character.isLetter(curr) == true)
{
count++;
}
}
return count;
}
public void firstCaps (String str)
{
String temp = " " + str ;
temp = temp.toLowerCase();
String newStr= "";
char prev , curr ;
for (int loop = 1; loop < temp.length()-1; loop++)
{
prev = temp.charAt(loop - 1);
curr = temp.charAt(loop);
if (Character.isLetter(prev)== false && Character.isLetter(curr)== true )
{
newStr = newStr + Character.toUpperCase(curr);
}
else
{
newStr = newStr + curr ;
}
}
}
public void removeVowels(String str)
{
String temp = " " + str ;
temp = temp.toLowerCase();
String newStr = " ";
char prev , curr ;
final String VOWELS = "aeiouAEIOU";
for (int i = 1; i < temp.length()-1; i++)
{
prev = temp.charAt(i-1);
curr = temp.charAt(i);
if (Character.isLetter(prev)== false && VOWELS.indexOf(temp.charAt(i))>= 0 || VOWELS.indexOf(temp.charAt(i))== - 1 )
{
newStr = newStr + temp.charAt(i);
}
}
str = newStr ;
}
private String encodeWord (String w )
{
final String VOWELS = "aeiouAEIOU";
if (VOWELS.indexOf(w.charAt(0))== -1 )
{
w = w.substring(1) + w.charAt(0);
}
w = w + "ay";
return w;
}
public void pigLatin (String str)
{
String singleWord, temp = " " + str + " ";
int begin = 0;
temp = temp.toLowerCase ();
String pigStr = " ";
char prev, curr;
for (int loop = 1; loop < temp.length ()-1; loop++)
{
prev = temp.charAt(loop-1);
curr = temp.charAt(loop);
if (Character.isLetter(prev) == false &&
Character.isLetter(curr) == (true))
{
begin = loop;
}
if (Character.isLetter(prev) == true &&
Character.isLetter(curr) == (false))
{
singleWord = temp.substring (begin,loop);
pigStr = pigStr + encodeWord (singleWord) + " ";
}
}
}
public String reverse(String str){
int strLeng = str.length()-1;
String reverse = "", temp = "";
for(int i = 0; i <= strLeng; i++){
temp += str.charAt(i);
if((str.charAt(i) == ' ') || (i == strLeng)){
for(int j = temp.length()-1; j >= 0; j--){
reverse += temp.charAt(j);
if((j == 0) && (i != strLeng))
{
reverse += " ";
}
}
temp = "";
}
}
return reverse;
}
}
我遇到的问题是从同一个包中的 JFrame 访问这些方法,我试过了
StringToolsNS123 str = new StirngToolsNS123 () ;
但它给出了一个错误,说找不到类?
提前致谢!