0
Best way to Store and get Values from a list
Hi guys, i am sorry if my question is misleading as i dont know how to write it properly. i am new to coding =) I want to store 2 different Values. The first Value (x) Starts with 10 and the Second Value (y) Starts with 70. Every time x gets 10 points higher i want to increase y with +1 I made a for loop and it works fine so far. (With Console Output) My question is how can i store this somewhere. Should i store it in a fixed Database? Later on i want to get the Value of y when i just type in x. Maybe you could give me a hint on what to do (i am trying to write a little program, so please dont just post code as i want to learn it myself) Thanks in Advance :)
3 Answers
+ 2
Arrays:
int[] numbers = new int [2]
numbers [0] = x;
numbers [1] = y;
or if you know the values at the beginning:
int [] numbers = {10,70}
for (int i = 0; i < numbers.length; i++){
System.out.println (numbers [i]);
}
ArrayList:
import java.util.ArrayList;
ArrayList numbers = new ArrayList ();
numbers.add (10);
numbers.add (70);
System.out.println (numbers);
to get a single digit:
int i = numbers.get (0); //10
i = numbers.get (1); //70
+ 1
in javascript put the new value from the loop in a new variable. that variable can be called on any time..and will always update with the new number.
+ 1
I am Doing this in C# but i Think it should be similar. I will try :)