java编程出现The operator >= is undefined for the argument type(s) char[], char的错误
packagelianxi01;importjava.util.*;publicclasstest07{publicstaticvoidmain(String[]args...
package lianxi01;
import java.util.*;
public class test07 {
public static void main(String[] args){
int digital=0;
int character=0;
int other=0;
int blank=0;
char[] ch=null;
Scanner sc;
String s =sc.nextLine();
ch=s.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(ch>='0'&&ch<='9'){
digital++;
}
else if((ch>='a'&&ch<='z')||ch>'A'&&ch<='Z'){
character++;
}
else if(ch==' '){
blank++;
}else{
other++;
}
}
System.out.println("数字个数:"+digital);
System.out.println("英文字母个数:"+character);
System.out.println("空格个数:"+blank);
System.out.println("其他字符个数:"+other);
}
} 展开
import java.util.*;
public class test07 {
public static void main(String[] args){
int digital=0;
int character=0;
int other=0;
int blank=0;
char[] ch=null;
Scanner sc;
String s =sc.nextLine();
ch=s.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(ch>='0'&&ch<='9'){
digital++;
}
else if((ch>='a'&&ch<='z')||ch>'A'&&ch<='Z'){
character++;
}
else if(ch==' '){
blank++;
}else{
other++;
}
}
System.out.println("数字个数:"+digital);
System.out.println("英文字母个数:"+character);
System.out.println("空格个数:"+blank);
System.out.println("其他字符个数:"+other);
}
} 展开
2016-07-15
展开全部
修改后的代码:
import java.util.*;
public class test07 {
public static void main(String[] args) {
int digital=0;
int character=0;
int other=0;
int blank=0;
char[] ch=null;
Scanner sc = new Scanner(System.in); //修改一下
String s =sc.nextLine();
ch=s.toCharArray();
for(int i=0; i<ch.length; i++) {
//下面的ch改为ch[i]
if(ch[i] >= '0'&&ch[i] <= '9') {
digital++;
} else if((ch[i] >= 'a'&&ch[i] <= 'z')||ch[i] >= 'A'&&ch[i] <= 'Z') {
character++;
} else if(ch[i] == ' ') {
blank++;
} else {
other++;
}
}
System.out.println("数字个数:"+digital);
System.out.println("英文字母个数:"+character);
System.out.println("空格个数:"+blank);
System.out.println("其他字符个数:"+other);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询