(30) The title @java blue bridge 15 Cup Group B Exercise Basics: String Comparison

(30) The title @java blue bridge 15 Cup Group B Exercise Basics: String Comparison

Keywords: string, case

Problem Description

Given two strings of only uppercase or lowercase letters (a length between 1 and 10), the relationship between them is one of the following 4 conditions:
  unequal length two strings: 1. For example Beijing and Hebei
  2: only two strings of equal length, but also the character at the corresponding position exactly (case sensitive), such as Beijing and Beijing
  . 3: two strings of equal length, only the character at a corresponding position are not distinguished under the premise of the case in order to achieve exactly the same (that is, it does not meet the case 2). For example beijing and beijing
  . 4: the length of the two strings are equal, but even these can not case sensitive nor two identical strings. Beijing and Nanjing such
  a relationship between two input strings programming determines which category of these four given class number belongs.
Input format
  includes two rows, each row is a string of
output format
  is only one digit, showing the relationship of these two numbering character string
Sample Input
beijing
beijing
Sample Output
3

Code:

java.util.Scanner Import;
public class the Main {
public static void main (String [] args) {
Scanner Scanner new new = S (the System.in);
String zifu1 s.next = ();
String zifu2 = s.next () ;
int changdu1 = zifu1.length ();
int changdu2 = zifu2.length ();
IF (changdu1> =. 1 && changdu1 <= 10 && changdu2> =. 1 && changdu2 <= 10) {
fangFa (zifu1, zifu2);
}
}
public static void fangFa ( n-string, string m) {
int K = 0;
IF (n.length () == m.length ()) {// two strings of the same length
if (n.equals (m)) { // two exact string
K = 2;
} the else IF (banXiangSi (n-, m)) {// the two strings in the case of excluding the case where the same (similar half)
K =. 3;
} // only the else {length the same
K =. 4;
}
} the else {// two completely different strings
k = 1;
}
System.out.println (K);
}
public static Boolean banXiangSi (n-String, String m) {// string is determined whether two similar half
Boolean = T to true;
String newA n.toLowerCase = ();
String newb m.toLowerCase = ();
IF (newA.equals (newb)) {
T = to true;
} the else {
T = to false;
}
return T;
}
}

Published 29 original articles · won praise 1 · views 1091

Guess you like

Origin blog.csdn.net/DAurora/article/details/104278596