0
Something look wrong in this code
This my code , whenever i need to change x value of object ofdr this error pops up. import java.util.Scanner; public class Class { Class (double x,double b,double c) { } public static void main(String[] args) { double x2; double b2; double c2, d2; Scanner xt = new Scanner(System.in); System.out.println("x ادخل قيمة "); x2 = xt.nextInt(); Class ofdr = new Class(0,0,0); x.ofdr = 5; } } The error is like this javac Class.java Class.java:21: error: cannot find s ymbol x.ofdr = 5; ^ symbol: variable x location: class Class 1 error Process exited with code: 1
4 Antworten
+ 7
x is neither an object nor it is declared in your class. That's why the error "Cannot find symbol" x in your class named Class.
If you just want to change the value then try something like this..for now..
public class Class {
double x; // declaring instance variable x.
public static void main (String [] args) {
Class obj = new Class (); // creating a Class object named obj.
obj.x = 5; // assigning value to obj's instance variable x.
System.out.println (obj.x);
}
}
Later you might want to take a look into getters and setters.
https://www.sololearn.com/learn/Java/2154/
+ 1
Can you explain to me what you are trying to do?
+ 1
Ipang i’m trying to change x value of object ofdr
+ 1
1, you put double inside class arguments, but when you assign put integer
2, try ofdr.x=5.0;