Below is the script i wrote to attempt to input a list of numbers(integers) and assign it to a variable
import java.util.ArrayList;
import java.util.Arrays;
public class AssignList
{
public static void main(String[] args)
{
//int[] b =Arrays.toString(args); //my attempt to assign an input to variable b
System.out.println(Arrays.toString(args));
int[] a = {5, 2, 4, 1}; //how to print out integers
System.out.println(Arrays.toString(a));
}
}
i can input and print out a list of numbers but i haven't been able to figure out how to assign it to a variable.
I dont mean my question is necessarily different from the one linked by the commenter, it's just i havent been able to figure it out even after looking at it.
I think the format of args
is java.lang.String. Assuming that one will execute the script by typing java AssignList 5241
, i would like to be able to assign the input 5241
as an array so that i can pick out each element by indexing.