import java.io.DataInputStream;
import java.io.IOException;
import java.util.*;public class Count {
public static void main(String[] args) {
String str = null;
int a = 0,b = 0,c= 0,d = 0,e = 0,f = 0,g = 0,h = 0,i = 0,j = 0,k = 0,l = 0,m = 0,n = 0,o= 0,p = 0,q = 0,r = 0,s = 0,t = 0,u = 0,v = 0,w = 0,x = 0,y = 0,z = 0;
System.out.print(System.in);
DataInputStream dis = new DataInputStream(System.in);
try {
str = dis.readUTF();
} catch (IOException ie) {
ie.printStackTrace();
}
for(int is=0;is<str.length();i++) {
char ch = str.charAt(is);
switch(ch) {
case 'A':
a++;
System.out.println("a count"+a);
break;
case 'B':
b++;
System.out.println("b count"+b);
break;
case 'C':
c++;
System.out.println("c count"+c);
break;
case 'D':
d++;
System.out.println("d count"+d);
break;
case 'E':
e++;
System.out.println("e count"+e);
break;
case 'F':
f++;
System.out.println("f count"+f);
break;
case 'G':
g++;
System.out.println("g count"+g);
break;
case 'H':
h++;
System.out.println("h count"+h);
break;
case 'I':
i++;
System.out.println("i count"+i);
break;
case 'J':
j++;
System.out.println("j count"+j);
break;
case 'K':
k++;
System.out.println("k count"+k);
break;
case 'L':
l++;
System.out.println("l count"+l);
break;
case 'M':
m++;
System.out.println("m count"+m);
break;
case 'N':
n++;
System.out.println("n count"+n);
break;
case 'O':
o++;
System.out.println("o count"+o);
break;
case 'P':
p++;
System.out.println("p count"+p);
break;
case 'Q':
q++;
System.out.println("q count"+q);
break;
case 'R':
r++;
System.out.println("r count"+r);
break;
case 'S':
s++;
System.out.println("s count"+s);
break;
case 'T':
t++;
System.out.println("t count"+t);
break;
case 'U':
u++;
System.out.println("u count"+u);
break;
case 'V':
v++;
System.out.println("v count"+v);
break;
case 'W':
w++;
System.out.println("w count"+w);
break;
case 'X':
x++;
System.out.println("x count"+x);
break;
case 'Y':
y++;
System.out.println("y count"+y);
break;
case 'Z':
z++;
System.out.println("z count"+z);
break;
}
}
}
}
这是一个数字符串中个字母的个数的程序,但是一直报java.io.BufferedInputStream@35ce36 这个错误,不知道什么问题,哪位高手解答一下。另外如果把26个英文字母放在ENUM类型中,就会报The member enum Para cannot be local.例如就这样
enum Para {A,B},就会报以上错误,哪位高手提点一下。谢谢了
import java.io.IOException;
import java.util.*;public class Count {
public static void main(String[] args) {
String str = null;
int a = 0,b = 0,c= 0,d = 0,e = 0,f = 0,g = 0,h = 0,i = 0,j = 0,k = 0,l = 0,m = 0,n = 0,o= 0,p = 0,q = 0,r = 0,s = 0,t = 0,u = 0,v = 0,w = 0,x = 0,y = 0,z = 0;
System.out.print(System.in);
DataInputStream dis = new DataInputStream(System.in);
try {
str = dis.readUTF();
} catch (IOException ie) {
ie.printStackTrace();
}
for(int is=0;is<str.length();i++) {
char ch = str.charAt(is);
switch(ch) {
case 'A':
a++;
System.out.println("a count"+a);
break;
case 'B':
b++;
System.out.println("b count"+b);
break;
case 'C':
c++;
System.out.println("c count"+c);
break;
case 'D':
d++;
System.out.println("d count"+d);
break;
case 'E':
e++;
System.out.println("e count"+e);
break;
case 'F':
f++;
System.out.println("f count"+f);
break;
case 'G':
g++;
System.out.println("g count"+g);
break;
case 'H':
h++;
System.out.println("h count"+h);
break;
case 'I':
i++;
System.out.println("i count"+i);
break;
case 'J':
j++;
System.out.println("j count"+j);
break;
case 'K':
k++;
System.out.println("k count"+k);
break;
case 'L':
l++;
System.out.println("l count"+l);
break;
case 'M':
m++;
System.out.println("m count"+m);
break;
case 'N':
n++;
System.out.println("n count"+n);
break;
case 'O':
o++;
System.out.println("o count"+o);
break;
case 'P':
p++;
System.out.println("p count"+p);
break;
case 'Q':
q++;
System.out.println("q count"+q);
break;
case 'R':
r++;
System.out.println("r count"+r);
break;
case 'S':
s++;
System.out.println("s count"+s);
break;
case 'T':
t++;
System.out.println("t count"+t);
break;
case 'U':
u++;
System.out.println("u count"+u);
break;
case 'V':
v++;
System.out.println("v count"+v);
break;
case 'W':
w++;
System.out.println("w count"+w);
break;
case 'X':
x++;
System.out.println("x count"+x);
break;
case 'Y':
y++;
System.out.println("y count"+y);
break;
case 'Z':
z++;
System.out.println("z count"+z);
break;
}
}
}
}
这是一个数字符串中个字母的个数的程序,但是一直报java.io.BufferedInputStream@35ce36 这个错误,不知道什么问题,哪位高手解答一下。另外如果把26个英文字母放在ENUM类型中,就会报The member enum Para cannot be local.例如就这样
enum Para {A,B},就会报以上错误,哪位高手提点一下。谢谢了
解决方案 »
- 如何把List中的数据按某一字段排序
- 求解!数组插入新元素问题。
- jTextField中字体保存问题
- 互斥锁的问题?
- public static void main(String args [] ) ,String args []的作用是什么?
- BigDecimal.dive(one,scale,BigDecimal.ROUND_HALF_UP)不能四舍五入!!
- 请问怎样得到图形的COPY,使用CLONE()
- 纯小白问下:如果我想把一组数据上传到服务器,是用socket实现么?
- 怎么识别中文页面???急!!!!!!!
- 刚开始,JAVA怎么学??
- 正则表达式的问题?
- 如何判断一个英文单词为专用名词?
另外,你程序我运行不明白,帮你写了个,不知道是你要的意思不
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Test1 { public static void main(String[] args) {
//构建一个map,初始化数据,每个字母数量都是0
Map<String, Integer> map = new HashMap<String, Integer>();
String[] arr = {"A","B","C","D","E","F",
"G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T",
"U","V","W","X","Y","Z"};
for(int i=0;i<arr.length;i++){
map.put(arr[i], 0);
} //获取输入的字符串
Scanner s = new Scanner(System.in);
String str = s.nextLine();
//将字符串拆分
List<String> list = new ArrayList<String>();
for(int i=0;i<str.length();i++){
list.add(str.substring(i, i+1));
}
//查数量
for(int i=0;i<list.size();i++){
String word = list.get(i);
int count = map.get(word);
map.remove(word);
count++;
map.put(word, count);
}
//遍历map
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]+"字母数量有:"+map.get(arr[i]));
}
}
}
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferReadered(in);String str=null; //可更改为其他数据类型try{
str=br.readline();
}catch(IOException e){
e.printStackTrace();
}你想实现接收键盘输入,但是你写的只是接收键盘的字母,而且也不能那样写吧
另外从键盘输入跟eclipse没关系,完全是程序来控制的,具体看5楼