高分求解 JAVA高手们进
随机产生1000个大写字母,统计各字母出现的次数,并且按字母顺序打印出其出现次数例如A:50B:34...高人们你们八仙过海各显神通哈答案都很完美这让我很难办啊该采纳哪个...
随机产生1000个大写字母,统计各字母出现的次数,并且按字母顺序打印出其出现次数
例如
A:50
B:34
...
高人们 你们八仙过海各显神通哈
答案都很完美 这让我很难办啊
该采纳哪个好啊 展开
例如
A:50
B:34
...
高人们 你们八仙过海各显神通哈
答案都很完美 这让我很难办啊
该采纳哪个好啊 展开
3个回答
展开全部
public class main{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
r.StartToRun();
r.PrintOut();
}
}
class Random{
private int []letters;
public Random() {
letters = new int [26];
for(int i = 0; i < 26; i++){
letters[i] = 0;
}
}
public void StartToRun() {
for(int i = 0; i < 1000 ;i++) {
letters[(int)(Math.random()*26)]++;
}
}
public void PrintOut() {
int all = 0;
for(int i = 0; i < 26; i++) {
all += letters[i];
System.out.println((char)('A' + i) + " is :" + letters[i]);
}
System.out.println("all is " + all );
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
r.StartToRun();
r.PrintOut();
}
}
class Random{
private int []letters;
public Random() {
letters = new int [26];
for(int i = 0; i < 26; i++){
letters[i] = 0;
}
}
public void StartToRun() {
for(int i = 0; i < 1000 ;i++) {
letters[(int)(Math.random()*26)]++;
}
}
public void PrintOut() {
int all = 0;
for(int i = 0; i < 26; i++) {
all += letters[i];
System.out.println((char)('A' + i) + " is :" + letters[i]);
}
System.out.println("all is " + all );
}
}
展开全部
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test {
public static void main(String[] args) {
char a;
String str = "";
Pattern p = null;
Matcher m = null;
int count = 0;
for (int i = 0; i < 1000; i++) {
a = (char) (Math.round(Math.random() * 25) + 65);
str += a + "";
}
System.out.println(str);
for ( char reg = 'A'; reg <= 'Z'; reg++) {
p = Pattern.compile(reg + "");
m = p.matcher(str);
while (m.find()) {
count++;
}
System.out.print(reg + ":" + count + " ");
count = 0;
}
}
}
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test {
public static void main(String[] args) {
char a;
String str = "";
Pattern p = null;
Matcher m = null;
int count = 0;
for (int i = 0; i < 1000; i++) {
a = (char) (Math.round(Math.random() * 25) + 65);
str += a + "";
}
System.out.println(str);
for ( char reg = 'A'; reg <= 'Z'; reg++) {
p = Pattern.compile(reg + "");
m = p.matcher(str);
while (m.find()) {
count++;
}
System.out.print(reg + ":" + count + " ");
count = 0;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.Random;
public class Alpha {
public static void main(String... args) {
Random rand = new Random();
int alpha[] = new int[26];
int t;
for (int i = 0; i < 1000; i++) {
t = rand.nextInt();
alpha[Math.abs(t) % 26]++;
}
for (int j = 0; j < alpha.length; j++) {
System.out.println((char) (j + 65) + ": " + alpha[j]);
}
}
}
public class Alpha {
public static void main(String... args) {
Random rand = new Random();
int alpha[] = new int[26];
int t;
for (int i = 0; i < 1000; i++) {
t = rand.nextInt();
alpha[Math.abs(t) % 26]++;
}
for (int j = 0; j < alpha.length; j++) {
System.out.println((char) (j + 65) + ": " + alpha[j]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询