variables

variables retaining values after app close

只谈情不闲聊 提交于 2020-01-11 13:49:07
问题 My app is retaining all of the variable values when it closes and this is effecting how it runs when reopened. Is there any way to reset them all upon app close? or is there a way to clean the app from memory when it is closed so to speak? For the moment I have just been setting all of the important variables "=0" in the last few lines of execution but I know there must be a correct way to doing this. EDIT: OK I thought that it would just be easier to reply here instead of individually to

How to make user input relate to a variable?

血红的双手。 提交于 2020-01-11 13:15:50
问题 I don't know how to phrase this question precisely, but this is what I want to achieve (I am implementing the Towers of Hanoi illustration using stacks: This is inside the main() function: System.out.println("Type the source pole number and the destination pole number"); int a = reader.nextInt(); int b = reader.nextInt(); boolean move = moveDics(a, b); These are the stacks which represent the 3 poles: Stack<Integer> pole1 = new Stack<Integer>(); Stack<Integer> pole2 = new Stack<Integer>();

Local variables of same name in same scope, IDE display error but when I run the program, no run time error results

假装没事ソ 提交于 2020-01-11 13:13:29
问题 I understand that it is illegal to declare local variables of the same name in the same scope. I wrote this very simple class, and yes, the IDE does display an error next to int i = 10; . But when I run the code, everything seem to be fine. public class VariableWithSameName { static void myMethod(int i){ int i = 10; //error: variable i already defined in method } public static void main(String[] args){ } } It is only when I called myMethod did a run time error occurred. public class

Get variable name in jQuery [closed]

不打扰是莪最后的温柔 提交于 2020-01-11 12:59:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How can I get the name of a variable? Let's say I have an empty variable: var myvariable; How can I get the variable name so that this: alert(this_is_what_i_am_looking_for); will display: myvariable EDIT: Maybe I

“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

依然范特西╮ 提交于 2020-01-11 12:28:21
问题 I'm running a PHP script and continue to receive errors like: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10 Notice: Undefined index: my_index C:\wamp\www\mypath\index.php on line 11 Line 10 and 11 looks like this: echo "My variable value is: " . $my_variable_name; echo "My index value is: " . $my_array["my_index"]; What is the meaning of these error messages? Why do they appear all of a sudden? I used to use this script for years and I've never had

Variable Definition Ignore in C [duplicate]

放肆的年华 提交于 2020-01-11 11:13:23
问题 This question already has answers here : Variable definition inside switch statement (5 answers) Closed 2 years ago . Code: int main() { int a=1; switch(a) { int b=20; case 1: printf("b is %d\n",b); break; default: printf("b is %d\n",b); break; } return 0; } Output: It prints some garbage value for b when does the declaration of b takes place here Why b is not initialized with 20 here??? 回答1: Because memory will be allocated for int b but when the application is run " b = 20 " will never be

Variable Definition Ignore in C [duplicate]

半腔热情 提交于 2020-01-11 11:12:10
问题 This question already has answers here : Variable definition inside switch statement (5 answers) Closed 2 years ago . Code: int main() { int a=1; switch(a) { int b=20; case 1: printf("b is %d\n",b); break; default: printf("b is %d\n",b); break; } return 0; } Output: It prints some garbage value for b when does the declaration of b takes place here Why b is not initialized with 20 here??? 回答1: Because memory will be allocated for int b but when the application is run " b = 20 " will never be

How do I include a yet to be defined variable inside a string? PHP

杀马特。学长 韩版系。学妹 提交于 2020-01-11 10:54:07
问题 For sake of performing less database queries and for clarity of code, I'd like include a yet to be defined variable inside a string. Later in the page, the variable will be declared and the string printed and evaluated. How do i do this? $str="This $variable is delicious"; $array=array("Apple","Pineapple","Strawberry"); foreach($array as $variable) { print "$str"; } 回答1: You can use printf() (or sprintf() if you don't want to echo it): $str = 'This %s is delicious'; foreach ($array as

In Objective-C, are int variables that haven't been assigned a value nil?

余生长醉 提交于 2020-01-11 10:47:32
问题 If I have this in my .h file: int index; And then in the .m file I have: if (index == nil) and I haven't assigned a value to index , will that come up true? EDIT I guess nil is only used for objects. So what is the state of an int that hasn't been assigned a value? 回答1: There is no such thing as "nil" for ints. That's an object value. As for what variables are initialized to by default: Non-static local variables are not initialized to any defined value (in practice, they will usually have

is there a way to access a non-global shadowed variable in javascript

馋奶兔 提交于 2020-01-11 10:41:13
问题 I'm currently learning javascript scope and was just wondering whether it is possible to access a non-global shadowed variable in javascript? i.e. in the example below, the variable a that equal to 10 in the aFunc function var a = 1; function aFunc(){ var a = 10; function innerFunc(){ var a = 100; console.log("innerFunc a = " + a); console.log("is it possible to access outer function's a variable?"); console.log("global a = " + window.a); } innerFunc(); } aFunc(); ps - I understand naming