⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexof.java

📁 java程序设计 机械工业出版社 书籍代码
💻 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 + -