📄 indexof.java
字号:
import javax.swing.JOptionPane;
public class indexOf {
public static void main(String[] args) {
String a = JOptionPane.showInputDialog(
null, "输入第一个字符串:",
"习题7.3", JOptionPane.QUESTION_MESSAGE);
String b = JOptionPane.showInputDialog(
null, "输入第二个字符串:",
"习题7.3", JOptionPane.QUESTION_MESSAGE);
if (isSubstring(a, b)) {
String output1= a + "是" + b +"的子串";
JOptionPane.showMessageDialog(null,output1,"习题7.3输出",
JOptionPane.INFORMATION_MESSAGE);
}
else {
String output2 =a + "不是" + b +"的子串";
JOptionPane.showMessageDialog(null,output2,"习题7.3输出",
JOptionPane.INFORMATION_MESSAGE); }
}
public static boolean isSubstring(String c, String d) {
int remainingLength = d.length();
int startingIndex = 0;
toWhile: while (c.length() <= remainingLength) {
for (int i = 0; i < c.length(); i++) {
if (c.charAt(i) != d.charAt(startingIndex+i)) {
startingIndex++;
remainingLength--;
continue toWhile;
}
}
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -