我想用for循环遍历字母表并将每个字母添加到我的 HashMap
for(char alphabet = 'A'; alphabet <= 'Z';alphabet++) {
System.out.println(alphabet);
}
Run Code Online (Sandbox Code Playgroud)
不适合我,因为我HashMap的形式
HashMap<String, HashMap<String, Student>> hm;
Run Code Online (Sandbox Code Playgroud)
我需要我的迭代器是一个字符串,但是
for(String alphabet = 'A'; alphabet <= 'Z';alphabet++) {
System.out.println(alphabet);
}
Run Code Online (Sandbox Code Playgroud)
不起作用.
基本上,我想这样做:
for i from 'A' to 'Z' do
hm.put(i, null);
od
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要重载赋值/减量运算符( - =)以便代码
object -= int
Run Code Online (Sandbox Code Playgroud)
通过rhs上的值减少object.life.这是我的代码:
const Object& Object::operator -= (const Object& obj)
{
if (life == obj.life)`
{
this->life -= obj.life;
return *this;
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在我的主要实现这个?
int main()
{
Object o1;
o1 -= 5; //DOESNT WORK
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?谢谢
我有一个矩阵扁平成一维阵列.我怎么能把0所有的对角线放进去?例如,对于4x4矩阵,我试过这个(n=4)
int j = 1;
for (int i = 0; i < n*n; i++)
{
if (i % 4 == 0)
{
global_matrix[i + j] = 0;
j++;
}
}
Run Code Online (Sandbox Code Playgroud)
但我明白了
| 0 | 61 | 64 | 80 |
| 0 | 16 | 35 | 15 |
| 0 | 74 | 7 | 68 |
| 0 | 54 | 92 | 63 |
Run Code Online (Sandbox Code Playgroud) 我正在尝试评估一个字符:
bool repeat = true;
while (repeat)
//code
char x;
cout << "Would you like to tansfer another file? Y/N ";
cin >> x;
if (x == 'y' || x == 'Y')
repeat = true;
if (x == 'n' || x == 'N')
repeat = false;
else
throw "Input error";
Run Code Online (Sandbox Code Playgroud)
我一直得到输入错误作为我的控制台输出.有什么想法吗?我不能让while循环重复.