首页 > 其他 > 详细

字符串对比 BASIC-15

时间:2021-04-01 00:20:50      阅读:17      评论:0      收藏:0      [点我收藏+]

字符串对比

代码

import java.util.Scanner;

/*给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间),它们之间的关系是以下4中情况之一:
  1:两个字符串长度不等。比如 Beijing 和 Hebei
  2:两个字符串不仅长度相等,而且相应位置上的字符完全一致(区分大小写),比如 Beijing 和 Beijing
  3:两个字符串长度相等,相应位置上的字符仅在不区分大小写的前提下才能达到完全一致(也就是说,它并不满足情况2)。比如 beijing 和 BEIjing
  4:两个字符串长度相等,但是即使是不区分大小写也不能使这两个字符串一致。比如 Beijing 和 Nanjing
  编程判断输入的两个字符串之间的关系属于这四类中的哪一类,给出所属的类的编号。
 * */
public class 字符串对比 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String s1 = sc.next();
		String s2 = sc.next();
		
		int type = judgeType( s1, s2);
		System.out.println(type);
	}
	public static  int judgeType(String s1,String s2) {
		int type = -1;
		if(s1.length()!=s2.length()){
			type = 1;
		}else if(s1.equals(s2)) {
			type = 2;
		}else if(s1.toLowerCase().equals(s2.toLowerCase())) {
			type = 3;
		}else {
			type = 4;
		}
		return type;
	}

}

字符串对比 BASIC-15

原文:https://www.cnblogs.com/MyBlogForRecord/p/14603449.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!