求助!!!!!!相同的字符串为什么比较出来不一样
漂亮少年 2018-08-04 12:52:15 package String联系;
import java.util.Scanner;
import java.util.Random;
public class Suiji {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("输入一个长度:");
int a=sc.nextInt();
CsSj cc=new CsSj(a);
System.out.println("你的验证码:"+cc.fun());
System.out.print("输入验证码:");
String str=sc.next();
boolean is=str.equalsIgnoreCase(cc.fun());//比较两个字符穿
System.out.println(is);
}
}
//得到验证码的类
class CsSj {
int a;
public CsSj(int a) {//一参构造方法
this.a = a;
}
public String fun() {//得到一个a为字符串
String str = "";
for (int i = 0; i < a; i++) {
char b = (char) (Math.random() * 75 + 48);
if ((b > 47 && b < 58) || (b > 65 && b < 91) || (b > 96 && b < 123)) {
str += b;
} else {
for (int j = 1;; j++) {
char c = (char) (Math.random() * 75 + 48);
if ((c > 47 && b < 58) || (c > 65 && c < 91) || (c > 96 && c < 123)) {
str += c;break;
}
}
}
}
return str.trim();//返还字符串
}
}
为什么我输入与显示的字符串一样,还是给我false呢。