小编t3r*_*2d2的帖子

如何在Java中检查一个句子中有多少个辅音和元音?

在循环结束时,我计划显示句子中辅音和元音的数量。我想知道是否有一种更有效的方法来检查给定句子中有多少个辅音和元音,而不是使用 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)

java loops char

4
推荐指数
1
解决办法
6946
查看次数

矢量未知大小

我有一个 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)

我有一堆不相关的不同功能,所以我没有包括它们。

c++ vector header-files c++11

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

c++11 ×1

char ×1

header-files ×1

java ×1

loops ×1

vector ×1