Answer the question
In order to leave comments, you need to log in
Unable to convert double [] to class Main how to solve?
How to find out what type Main has and why it cannot cast it?
Throws an error:
Main.java:26: error: incompatible types: double[] cannot be converted to Main
public class Main
{
private double [] vektor;
public Main() {
double [] vektor = {2, 3.5, -5};
}
public Main plus (Main vektor){
double [] a = {2, 3.5, -5};
double [] b = {2, 3.5, -5};
double [] r = new double [a.length+b.length];
System.arraycopy(a, 0, r, 0, a.length);
System.arraycopy(b, 0, r, a.length, b.length);
return r;
}
}
Answer the question
In order to leave comments, you need to log in
Main has type Main.
It cannot result because there are no rules for transferring an array of doubles to main.
Question - what do you want from the Plus method? It does not use any input parameter, and for some reason it returns Main. The code is weird to say the least.
First part of the code
private double [] vector;
public Main() {
double [] vector = {2, 3.5, -5};
}
public Main plus (Main vector){
double [] a = {2, 3.5, -5};
double[] b = {2, 3.5, -5};
double [] r = new double [a.length+b.length];
System.arraycopy(a, 0, r, 0, a.length);
System.arraycopy(b, 0, r, a.length, b.length);
return r;
}
public Main(double [] vector) {
this. vector = vector;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question