我是Java的新手,所以如果这是一个愚蠢的问题我会道歉.
public static double FibonacciFinder(double number) {
double fibonacciNumber = ((1/sqrt(5))(Math.pow(((1+sqrt(5))/2),number)-(Math.pow(((1-sqrt(5))/2),number))));
return fibonacciNumber;
}
Run Code Online (Sandbox Code Playgroud)
我得到了以下回复
Fibonacci.java:29: error: ')' expected
double fibonacciNumber = ((1/sqrt(5))(Math.pow(((1+sqrt(5))/2),number)-(Math.pow(((1-sqrt(5))/2),number))));
^
Fibonacci.java:29: error: not a statement
double fibonacciNumber = ((1/sqrt(5))(Math.pow(((1+sqrt(5))/2),number)-(Math.pow(((1-sqrt(5))/2),number))));
^
Fibonacci.java:29: error: ';' expected
double fibonacciNumber = ((1/sqrt(5))(Math.pow(((1+sqrt(5))/2),number)-(Math.pow(((1-sqrt(5))/2),number))));
^
Run Code Online (Sandbox Code Playgroud)
我知道这不是计算方程式的最漂亮的方法,但究竟是什么才能打破我正在做的事情?有正确数量的括号和一切,所以我认为它至少会起作用.
我是C++的新手.我最近制作了一个在单独文件中使用类的小程序.我还想使用setter和getter(set&get)函数为变量赋值.当我运行程序时,编译器给我一个奇怪的错误.它说'string'没有命名类型.这是代码:
MyClass.h
#ifndef MYCLASS_H // #ifndef means if not defined
#define MYCLASS_H // then define it
#include <string>
class MyClass
{
public:
// this is the constructor function prototype
MyClass();
void setModuleName(string &);
string getModuleName();
private:
string moduleName;
};
#endif
Run Code Online (Sandbox Code Playgroud)
MyClass.cpp文件
#include "MyClass.h"
#include <iostream>
#include <string>
using namespace std;
MyClass::MyClass()
{
cout << "This line will print automatically because it is a constructor." << endl;
}
void MyClass::setModuleName(string &name) {
moduleName= name;
}
string MyClass::getModuleName() {
return moduleName;
} …Run Code Online (Sandbox Code Playgroud) Part part = request.getPart("file");
if (part != null){
String fileName = extractFileName(part);
String filePath = savePath + File.separator + fileName;
part.write(savePath + File.separator + fileName);
String imageName = fileName;
} else{
String fileName = "avatar.jpg";
String filePath = savePath + File.separator + fileName;
part.write(savePath + File.separator + fileName);
String imageName = fileName;
}
Run Code Online (Sandbox Code Playgroud)
在将if else语句插入代码后,我底部的代码收到此错误说:imageName无法解析为变量,filePath无法解析为变量.但是,一旦我评论了我的if else声明,一切都很好.有人能告诉我哪里出错了吗?
request.setAttribute("Pic", filePath);
request.setAttribute("PicName", imageName);
Run Code Online (Sandbox Code Playgroud) 在下面的示例中,编译器生成错误"使用未分配的局部变量r",即使我在使用它之前在循环中分配变量.为什么编译器会生成此错误?
static void Main(string[] args)
{
float r;
for (int i = 0; i < 100; i++)
r = i; // assigned here
Console.WriteLine(r); // error: use of unassigned local variable
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个C函数来模拟给定地址跟踪的缓存.使用gcc(真正的铿锵)在我的mac上编译时,该函数按预期工作.gcc --version在我的Mac上返回:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Run Code Online (Sandbox Code Playgroud)
当我使用gcc在linux上编译相同的程序时,返回是关闭的,我的程序中的eC&hC(缓存逐出计数器和命中计数器)是数十万,当它们应该低于10.当键入gcc时 - -version在linux机器上,它返回:
gcc(Ubuntu 4.9.3-8ubuntu2~14.04)4.9.3
这是程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <getopt.h>
#include "cachelab.h"
typedef struct{
int v;
int t;
int LRU;
} block;
typedef struct{
block *blocks;
} set;
typedef struct{
set *sets;
} cache;
void simulate(int s, int E, int b, char* file, int* hC, int* mC, int* eC)
{
int numSets = (1 << s);
char operation;
int …Run Code Online (Sandbox Code Playgroud) 我已经读过可以使用命令行编译多个链接的c ++文件g++ file1.cpp file2.cpp file3.cpp,依此类推.
但我的问题是:有没有办法在.txt文件中写入该文本,以便轻松更新?因为我觉得写每个文件名都很长而且不那么实用......
++有没有办法用Atom Editor编译多个c ++文件?我正在使用gpp-compiler包但我找不到让它工作的方法......
我是ARM平台的新手.
下面的代码已用于函数中,用于找出一些复数样本的共轭乘法并将其滑动到某些样本.
这段代码在linux 12.04版本的本机编译器中正常工作.在ARM中运行相同的代码时,它不会执行该功能.它只是从代码运行中退出.
#include<stdio.h>
int main()
{
float aa[12]={1,1,1,1,1,1,1,1,1,1,1,1};
float *x=aa,*y=x+6,real=0,imag=0;
fn_ComplexMultiply_addthem(x,y,6,&real,&imag);
printf("real value = %f\n",real);
printf("real value = %f\n",imag);
}
void fn_ComplexMultiply_addthem(float *x, float *y, float len, float *re, float *im)
{
int j;
for( j=0; j<len; j+=2)
{
*re += (x[j]*(y[j]));
*re -= (x[j+1]*(-y[j+1]));
*im += (x[j]*(-y[j+1]));
*im += (x[j+1]*(y[j]));
}
}
Run Code Online (Sandbox Code Playgroud)
我无法理解它的原因.每个指针指向一些值,然后它应该给我结果,无论什么可能是正确的.相反,它只是退出模拟.
是否会出现诸如堆栈或其他内存等其他问题?请帮我调试一下.
有谁能够帮我.
我试图从数组中排序字符串
var someArray= ["3a445a_V1", "3", "2a33s454_V1", "1", "3_V2", "2s4a34s3_V2", "234343"];
const [record] = someArray.map(r => parseFloat(r.replace('_V','.'))).sort((a,b) => a < b);
console.log(record)
//it returns 3a445a.1
Run Code Online (Sandbox Code Playgroud)
在浏览器console.log中它工作正常,而不是打字稿?
打字稿,它给出了以下错误 错误:
error TS2345: Argument of type '(a: number, b: number) => boolean' is not
assignable to parameter of type '(a: number, b: number) => number'.
Type 'boolean' is not assignable to type 'number'.
Run Code Online (Sandbox Code Playgroud)
任何的想法?提前致谢
我在memcpy上使用未声明的标识符'buffer'(buffer,&m_Text [index],m_Index - index); 并返回atof(缓冲区); char缓冲区[32] = {0}上的未使用变量'缓冲区'错误; 有没有办法解决这个问题?非常感谢
double GetNumber()
{
SkipWhitespaces();
int index = m_Index;
while (isdigit(m_Text[m_Index])) m_Index++;
if (m_Text[m_Index] == '.') m_Index++;
while (isdigit(m_Text[m_Index])) m_Index++;
if (m_Index - index == 0)
char buffer[32] = { 0 };
memcpy(buffer, &m_Text[index], m_Index - index);
return atof(buffer);
}
Run Code Online (Sandbox Code Playgroud) System.out.println("Hello, world!);
Run Code Online (Sandbox Code Playgroud)
(我知道规则,但想知道编译器是否投诉)
这会产生两个不同的错误消息,即使只有一个基础语法错误:
第一条消息: -
Hello.java:3: unclosed string literal <br>
System.out.println("Hello, world!);
Run Code Online (Sandbox Code Playgroud)
另一条消息: -
Hello.java:4: ')' expected before }
Run Code Online (Sandbox Code Playgroud) compiler-errors ×10
c++ ×3
java ×3
atom-editor ×1
c ×1
c# ×1
c++11 ×1
command-line ×1
compilation ×1
gcc ×1
javascript ×1
linux ×1
macos ×1
sorting ×1
typescript ×1