HI all I'm pretty new to this and just got hold of the instance and static variables.What i want to do is declare something inside as a static variable use it inside that class , assign a value to it by a user input , and do a calculation using that input and send this input inside another class (which doesn't have the main method ) and use it inside an array. Is it possible ? if so how ? from the way i did it it says that the variable can not be identified so obviously im wrong.I know i can do this using setter and getter but i dont know how to do so .Thank you so much in advance.What i have so far
public class Character {
public static int amount =0;
public void calculate(){
amount=sc.nextInt();
if(amount<0){
System.out.print("You are broke");
}
else{
System.out.print("You are ok You have"+amount);
}
}
Inside another class i want to use this amount
public class calculation2{
int [] arr=new int[amount];
public void smile(){
bla bla bla bla
}
}
How can i go about this , what am i dointwrong and any suggestions to fix it ? thank you so mumch
Character.amount.