java产生随机序列
public class English
{
public static void main(String[] args)
{
char ch='\0';
int count=0;
do
{
double x=Math.random()*100000;
int y=(int) x;
char z=(char)(y%26+65);
if(z!='A'&&Z!='E'&&Z!='O'&&Z!'U'&&Z!='I')
{
continue ;
}
System.out.printf(z+"\t");
count++;
}
while (count<26);
}
}
请问这个程序哪错了啊??求解
------解决方案--------------------大小写
if(z!='A'&&Z!='E'&&Z!='O'&&Z!'U'&&Z!='I')大小写混乱
------解决方案--------------------你这个是只输出aeiou吗? 怎么感觉怪怪的
------解决方案--------------------那你明显写错了
public static void main(String[] args) {
char ch = '\0';
int count = 0;
do {
double x = Math.random() * 100000;
int y = (int) x;
char z = (char) (y % 26 + 65);
if (z != 'A' && z != 'E' && z != 'O' && z != 'U' && z != 'I') {
System.out.printf(z + "\t");
count++;
}
} while (count < 26);
}
这样才对
------解决方案--------------------改成小写
你上面定义的z是小写 你下面在调用的时候肯定要一致小写呀
------解决方案--------------------
import java.util.Random;
public class Test01 {
static final char[] VOWEL_ARR = new char[]{'A','E','I','O','U'};
public static void main(String[] args) {
int count = 0;
Random random = new Random();
do {
int seed = random.nextInt(26);
char c = (char) ('A' + seed);
if(!isVowel(c)) {
System.out.print(c);
++count;
}
} while(count < 26);
}
static boolean isVowel(char c) {
for (int i = 0;i < VOWEL_ARR.length;++i) {
if(c == VOWEL_ARR[i]) {
return true;
}
}
return false;
}
}