duanqibo

 

import java.util.Scanner;

public class p78_7 {

  public static void main(String[] args)

  {

    int N=0,i=0;

    String str1=null;

    String str2=null;

    //从键盘输入字符串

    Scanner reader=new Scanner(System.in);

    System.out.print("从键盘输入两个字符串:\n");

    str1=reader.next();

    str2=reader.next();

    boolean flag=true;

    int n1=str1.length();

    int n2=str2.length();

    if(n1>n2)

      N=n1;

    else

      N=n2;

    while(i<N)

    {

      char ch1=str1.charAt(i);

      char ch2=str2.charAt(i);

      if(ch1==ch2)

        i++;

      else

      {

        System.out.print("两个字符串在第"+(i+1)+"个位置不相同!!\n");

        flag=false;

        break;

      }

    }

    System.out.print("两个字符串是否相同:"+flag);

    reader.close();

  } 

}

 

运行结果:

 

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2022-02-05
  • 2022-01-09
  • 2022-12-23
  • 2021-08-29
  • 2021-09-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-25
  • 2021-06-22
  • 2021-11-18
相关资源
相似解决方案