你好:)我是一名高三学生,今年对AP计算机科学产生了兴趣。我能够进入,但与其他人不同的是,我没有把必备知识带到这门课上,我也不太擅长编程。我们今天有一个作业,方向是找到一个"?“的索引。在字符串中(在第一个方法中),并在第二个方法中删除它。我试过了,但是失败了,哈哈,我知道我的代码是不正确的,我怎么才能按照说明正确地写这段代码呢?谢谢
import java.util.Scanner;
public class RemoveQuesRunner {
public void findQuestionMark() {
String s;
Scanner kb = new Scanner(in);
System.out.println("Enter word :: ");
String.indexOf(?)
}
public void removeQuestionMark() {
if (findQuestionMark()=true);
s.replace("?", "");
}
}
public void removeQuestionMark() {
if (findQuestionMark()=true);
s.replace("?", "");
}
}发布于 2016-11-04 13:50:50
不是完整的代码,因为我想让你再试一试。
public int findQuestionMark()
String s = kb.nextLine ();
int index = s.indexOf ('?');
return index;
...
public void removeQuestionMark(int index, String s)
if (findQuestionMark() != -1) {
return s.replace ("?", "");
}
return ("No ?");发布于 2016-11-04 13:59:25
我编辑了代码的一部分
public class Test {
public static String result;
public static void main(String[] args) {
findQuestionMark();
removeQuestionMark();
}
public static String findQuestionMark() {
Scanner input = new Scanner(System.in);
System.out.println("Enter word: ");
result = input.nextLine();
System.out.println("Index of ?: " + result.indexOf("?"));
return result;
}
public static void removeQuestionMark() {
result = result.replace("?", "");
System.out.println(result);
}
}发布于 2016-11-04 13:54:38
import java.util.Scanner;
public class RemoveQuesRunner
{
String s = "";
public int findQuestionMark()
{
Scanner kb = new Scanner(System.in);
System.out.println("Enter word :: ");
s=kb.next();
return s.indexOf("?");
}
public void removeQuestionMark(int index)
{
if(index >= 0)
{
StringBuilder bulid = new StringBuilder(str);
bulid.deleteCharAt(index);
str = bulid.toString();
}
}https://stackoverflow.com/questions/40416020
复制相似问题