zoukankan      html  css  js  c++  java
  • 自己写一个与startWith类似的判断方法

    
    

    package com.hanqi.lianxi;

    
    

    import java.util.Scanner;

    
    

    public class startWith
    {
            //自己顶一个与startWith类似的判断方法
     public static void main(String[] args)
     {
            //首先随便定义一个字符串如下
      String str = "fghkldrt";
      System.out.println("str="+"“"+str+"”");
      //提示我们自己输入一个字符串,用来判断输入的字符串是不是刚刚定义的字符串的开头
      Scanner sc = new Scanner(System.in);
      System.out.println("请输入您认为的字符串开头");
      String a =sc.nextLine();
      //通过indexOf来判断我们输入的字符串的索引号是否为0,若为0,则是开头,否则不是。
      int s =str.indexOf(a);
      if(s==0)
      {
       System.out.println("您输入的是字符串str的开头");
      }
      else
      {
       System.out.println("您输入的不是字符串str的开头");
      }
     }

    
    

    }

    
    

  • 相关阅读:
    Codeforces 691A Fashion in Berland
    HDU 5741 Helter Skelter
    HDU 5735 Born Slippy
    HDU 5739 Fantasia
    HDU 5738 Eureka
    HDU 5734 Acperience
    HDU 5742 It's All In The Mind
    POJ Euro Efficiency 1252
    AtCoder Beginner Contest 067 C
    AtCoder Beginner Contest 067 D
  • 原文地址:https://www.cnblogs.com/HRZJ/p/5870896.html
Copyright © 2011-2022 走看看