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

14th Dec 2020, 12:25 AM
Khaled Almutairi
4 odpowiedzi
+ 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/
14th Dec 2020, 2:18 AM
Minho
Minho - avatar
+ 1
Can you explain to me what you are trying to do?
14th Dec 2020, 12:57 AM
Ipang
+ 1
Ipang i’m trying to change x value of object ofdr
14th Dec 2020, 1:50 AM
Khaled Almutairi
+ 1
1, you put double inside class arguments, but when you assign put integer 2, try ofdr.x=5.0;
14th Dec 2020, 2:11 AM
Shadoff
Shadoff - avatar