将从控制台输入获取的字符串与数组中的字符串进行比较时,false除非我添加,否则总是这样.toString().两个字符串都是相同的,它应该工作而不添加.toString().任何人都可以帮我找出原因吗?
在这里,我从控制台获取要比较的字符串:
System.out.println("\nEnter the name you wish to remove from the list.");
String name = in.nextLine();
System.out.println("\n\"" + myNameList.remove(new MyOrderedList(name)) + "\"" + " removed from the name list\n");
Run Code Online (Sandbox Code Playgroud)
这是删除方法:
public T remove(T element) {
T result;
int index = find(element);
if (index == NOT_FOUND) {
throw new ElementNotFoundException("list");
}
result = list[index];
rear--;
/** shift the appropriate elements */
for (int scan = index; scan < rear; scan++) {
list[scan] = list[scan+1];
} …Run Code Online (Sandbox Code Playgroud) 我无法cout显示小数(使用eclipse c ++和mingw)
#include <iostream>
using namespace std;
int main() {
int a = 55, b = 60, c = 70;
double avgResult;
avgResult = ((a + b + c) / 3);
cout << avgResult; //should display 61.666666
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的输出是61,当我预计它是61.666666.
我可以使用它来显示小数
cout << std::fixed << std::setprecision(2) << avrResult;
但我想我不需要这样做,除非我想要一个特定的小数精度.
如果我做的事情
double value = 12.345;
cout << value;
Run Code Online (Sandbox Code Playgroud)
它显示正确,所以它让我相信上述问题与int我计算中的值的使用有关double avgResult
顺便说一下我是c ++的新手,我刚刚开始学习