Operate.java:
import java.util.Scanner;
public class Operate {
public boolean show()
{
int j=0;
System.out.println("請輸入密碼:");
Scanner input=new Scanner(System.in);
String ss=input.next();
char a[]=ss.toCharArray();
for(int i=0;i
{if(a[i]>='a'&&a[i]<='z')
{System.out.println("xiao ");
return false;}
if(a[i]>='A'&&a[i]<='Z'){
System.out.println("da");
return false;
}
}
return true;}
}
public class Test {
public static void main(String[] args) {
while(true)
{
Operate op=new Operate();
boolean b=op.show();
if(b)
{
System.out.println("ok");
break;
}
}
}
}
輸入Aa或者aA沒有提示ok!麻煩解決一下,我是新手!
用String的方法equalsIgnoreCase()就行了 這個方法是對比String忽略大小寫