在循环结束时,我计划显示句子中辅音和元音的数量。我想知道是否有一种更有效的方法来检查给定句子中有多少个辅音和元音,而不是使用 if 语句并手动输入每个字母。(key指的是我已经初始化的扫描仪)
编辑:它需要忽略数字和其他特殊字符,例如,如果我写 Hello@ how 1are you?。应该有8个元音和6个辅音。
System.out.println("Please enter the sentence to analyze: ");
String words = key.nextLine(); //the sentence the user inputs
int c = 0; //# of consonants
int v = 0; //# of vowels
int length = words.length(); //length of sentence
int check; //goes over each letter in our sentence
for(check = 0; check < length; check++){
char a = words.charAt(check);
if(a == 'a' || a == 'A' || a == 'e' || a == 'E' …Run Code Online (Sandbox Code Playgroud) 我有一个 Player 类,其中包含一个实例变量:\
vector<Card> userCards;
Run Code Online (Sandbox Code Playgroud)
为了避免任何编译错误,我向前声明了该类Card。但是现在当我尝试构建解决方案时,我收到一条错误消息
卡*:尺寸未知。
基本上我试图创建一个Player包含非固定数量的卡片的 who,所以我尝试使用向量,但现在我无法让它工作。
播放器.h
#include <iostream>
#include <vector>
using std::string;
using std::vector;
#ifndef PLAYER_H_
#define PLAYER_H_
class Card;
class Player {
private:
vector<Card> userCards;
};
#endif
Run Code Online (Sandbox Code Playgroud)
卡.h
#include <iostream>
using std::string;
#ifndef CARD_H_
#define CARD_H_
class Card {
private:
string name;
string type;
public:
Card(const string& name, const string& type);
};
#endif
Run Code Online (Sandbox Code Playgroud)
我有一堆不相关的不同功能,所以我没有包括它们。