我要解决一个小问题: 对于给定的字符数组,
char[] lista = {'a', '2', '?', 'd', '!', 'S', '3', 'D', 'k'};
我必须:
- 仅打印元音;
- 仅打印辅音;
- 打印数字并;
- 打印其他符号。
我在 4 中遇到问题。
到目前为止我的代码:
public class Teste {
public static void main(String[] args) {
char [] lista = {'a', '2', '?', 'd', '!', 'S', '3', 'D', 'k'};
char [] vogal = {'a', 'e', 'i', 'o','u','A','E','I','O','U'};
char [] numbers = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
char [] leters = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z','B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z'};
char [] symbols = {'a', 'e', 'i', 'o','u','A','E','I','O','U','1', '2', '3', '4', '5', '6', '7', '8', '9', '0','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z','B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z'};
for (char j=0; j<lista.length ; j++)
for (char i=0; i<vogal.length ; i++ ){
if ( vogal [i] == lista [j] )
System.out.println( "the vowels are: " + vogal [i] );
}
for (char j=0; j<lista.length ; j++)
for (char x=0; x<numbers.length ; x++ ) {
if ( numbers [x] == lista [j] )
System.out.println( "the numbers are: " + numbers [x] );
}
for (char j=0; j<lista.length ; j++)
for (char y=0; y<leters.length ; y++ ) {
if ( leters [y] == lista [j] )
System.out.println( "the leters are: " + leters [y] );
}
//my main problem is here
for (char j=0; j<lista.length ; j++)
for (char z=0; z<symbols.length ; z++ ){
if (symbols [z] != lista [j])
System.out.println( "the symbols are: " + lista [j]);
}
}
}
关于如何打印符号有什么建议吗? 谢谢。
最佳答案
的倒数
- 如果引用集中至少有一个(例如符号)匹配,则打印
不是
- 如果引用集中至少有一个不匹配,则打印
但是
- 如果引用集中没有匹配项,则打印。
换句话说,只要 lista[j]
等于 symbols[z]
就应该中断 z 上的内部循环,并且只打印它是一个一旦您在 symbols
中找不到匹配项,就可以使用符号。
(我不会在这里提供明确的代码,因为这是家庭作业)
关于java - 从字符数组打印符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9754147/