StringApp.detectWord();
StringApp.detectLetter();这两个是不是你自己定义的方法阿?
在String的API里面好像没有这两个方法阿至于length
改成length()还有chatAt
改成charAt
注意方法名
StringApp.detectLetter();这两个是不是你自己定义的方法阿?
在String的API里面好像没有这两个方法阿至于length
改成length()还有chatAt
改成charAt
注意方法名
你的这两个方法
参数是String数组
你有没有传递一个
String[] 类型的进取阿?
检查一下是不是你传递了一个String进去而已
如何用java编出一个程序使得
1 可输出其任意一部分,即任意单词
2 定位输出 即可输出任意一个字母
*/class StringApp {
String sen = "xtj is a king of pop";
String[] word = {"xtj","is","a","king","of","pop"};
public static void main(String[] args) {
int func;
System.out.println("function select:\n" + "\t\"1\" to select the word you want\n"
+ "\t\"2\" to select the letter you want");
if (args.length() > 0)
func = Integer.parseInt(args[0]);
switch (func) {
case 1: StringApp.detectWord();
break;
case 2: StringApp.detectLetter();
break;
}
}
void detectWord(String[] args) {
int num;
System.out.println(sen);
System.out.println(word.length() + "word(s) in this sentence.\n" +
"which one do you prefer to select?");
if (args.length() > 0)
num = Integer.parseInt(args[0]);
System.out.println("The word you selected is" + word[num]);
}
void detectLetter(String[] args) {
int sit;
System.out.println(sen);
System.out.println(sen.length() + "letter(s) in this sentence.\n" +
"which one do you prefer to select?");
if (args.length() > 0)
sit = Integer.parseInt(args[0]);
System.out.println("The letter you selected is" + sen.charAt(sit));
}
}
void detectLetter(String[] args) {
这些,其实方法里面不一定要有参数的
由参数也不一定就是
String[] args如果你这个是在JSP里面调用的话
就不要用System.out了