java 输出一个有汉字、数字和字母的数组里的汉字、数字和字母?用Ascii码判断,数组是给定的。
mip版 关注:206 答案:3 悬赏:60
解决时间 2021-01-22 06:19
已解决
2021-01-22 02:27
java 输出一个有汉字、数字和字母的数组里的汉字、数字和字母?用Ascii码判断,数组是给定的。
最佳答案
2021-01-22 02:55
public static void justArrElement(String[] arr){
int len = arr.length;
String chinese[] = new String[len]; //汉字
String number[] = new String[len]; //数字
String letter[] = new String[len]; //字母
String other[] = new String[len]; //汉字,数字,或字母的组合
int k=0; //chinese[]元素的个数
int l=0; //number[]元素的个数
int m=0; //letter[]元素的个数
int n=0; //other[]元素的个数
String str = "";
for(int i=0;i
{
str = arr[i];
if(isNum(str)){
number[l++] = str;
}else if(isLetter(str)){
letter[m++] = str;
}else if(isChinese(str)){
chinese[k++] = str;
}else{
other[n++] = str;
}
}
System.out.print("汉字:");
for(int i=0;i
System.out.print(chinese[i]+" ");
}
System.out.println();
System.out.print("数字:");
for(int i=0;i
System.out.print(number[i]+" ");
}
System.out.println();
System.out.print("字母:");
for(int i=0;i
System.out.print(letter[i]+" ");
}
System.out.println();
System.out.print("其他:");
for(int i=0;i
System.out.print(other[i]+" ");
}
System.out.println();
}
//判断字符串是不是纯数字
public static boolean isNum(String ss) {
for (int i = 0; i < ss.length(); i++) {
char a = ss.charAt(i);
if (a < '0' || a > '9') {
return false;
}
}
return true;
}
//判断字符串是不是纯字母
public static boolean isLetter(String ss) {
for (int i = 0; i < ss.length(); i++) {
char c = ss.charAt(i);
if ((c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z')) {
}else{
return false;
}
}
return true;
}
//判断字符串是不是纯汉字
public static boolean isChinese(String ss) {
for (int i = 0; i < ss.length(); i++) {
char c = ss.charAt(i);
if (19968 <= c && c <40623) {
}else{
return false;
}
}
return true;
}
public static void main(String[] args) {
String a[] = {"hahahhHHHaa","WWWhhs","437265","一","哇哈哈","abc123","哈22","ab你"};
justArrElement(a);
}
运行结果:
汉字:一 哇哈哈
数字:437265
字母:hahahhHHHaa WWWhhs
其他:abc123 哈22 ab你
全部回答
1楼
2021-01-22 04:51
import java.util.Scanner;
public class BoBo {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
System.out.println("请输入:");//注意输入是中间不能有空格
String s1 = scanner .next();
char cs[] = s1.toCharArray();
String str2="";
for(int i=0;i
{
if(Character.isUpperCase(cs[i]))
{
System.out.println("第"+(i+1)+"个字符是大写字母");
}else if(Character.isLowerCase(cs[i]))
{
System.out.println("第"+(i+1)+"个字符是小写字母");
}else if(Character.isDigit(cs[i]))
{
System.out.println("第"+(i+1)+"个字符是数字");
}else if(19968 <= cs[i] &&cs[i] <40623)
{
System.out.println("第"+(i+1)+"个字符是中文");
}
}
}
}例如可输入:123432GVGSVGvxgavh你好吗
2楼
2021-01-22 04:08
import java.io.bufferedreader;
import java.io.ioexception;
import java.io.inputstreamreader;
public class numberin1 {
public static void main(string[] args) {
// todo auto-generated method stub
byte numbers[] = null;
string input="";
bufferedreader reader = new bufferedreader(new inputstreamreader(system.in));
system.out.print("请输入: ");
try {
input = reader.readline();
numbers = input.getbytes();
} catch (numberformatexception e) {
// todo auto-generated catch block
e.printstacktrace();
} catch (ioexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
for(int j = 0;j
联系企业供求网
Copyright(©) 2020 企业供求网™版权所有