我有一个阅读文件并输出平均考试成绩的作业.
这很简单,但我不喜欢平均值是如何完成的.
average = (test1 + test2 + test3 + test4 + test5) / 5.0;
Run Code Online (Sandbox Code Playgroud)
有没有办法让它除以测试分数?我在书中或谷歌找不到这样的东西.就像是
average = (test + test + test + test) / ntests;
Run Code Online (Sandbox Code Playgroud) 可能重复:
如何阻止C++控制台应用程序立即退出?
我想看看我的结果,我该怎么做我的代码所以我可以看看我做的是否正确?
#include <iostream>
using namespace std;
int main()
{
cout << "C++" << endl;
cout << "The sum of 11 + 12 = " << 30/2 << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 例如,我正在尝试做这样的事情
public class Test {
public static void main(String args[]) {
int[] arr = new int[5];
arrPrint(arr);
}
public void arrPrint(int[] arr) {
for (int i = 0; i < arr.length; i++)
System.out.println(arr[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,告诉我无法从静态环境中引用非静态变量.所以,如果这是真的,我怎么能在主要内部使用非静态方法?
我正在尝试创建自己的类,其中一个参数是一个数组.
public class Node {
int i;
String title;
int[] links;
Node(int i, String title, int[] links){
this.i = i;
this.title = title;
this.links = links;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以做这个吗?我想做一些像Node(4,"Title",[1,2,3])之类的东西来调用它
我不知道发生了什么,但我无法得到这个.
我已经做了很多非常相似的问题,但由于某些原因我无法得到这个问题.
我正试图做一个反击.
(define (make-counter init)
(let ((count init))
((lambda (x)
(begin (set! count (+ count x)) count))1)))
Run Code Online (Sandbox Code Playgroud)
它不会起作用.我如何将状态引入其中?我不知道我以为我知道但它不起作用.我认为创建一个像这样的局部变量会使它工作,但事实并非如此,无论我做什么,价值永远不会改变.我的问题是使初始值可调,我可以让它工作没有它,但不是.