'How do the user input space separated values get stored until they are assigned to the variable in the next iteration in java?
Consider the following code;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i=0;i<5;i++) {
int n = in.nextInt();
System.out.print(v);
}
}
}
For the above code, if we enter the input by giving some random numbers separated by a space; eg: 7 8 9, then the output will be shown as '789'. After that there will only be 2 iterations left to go. I figured that when we input some values separated by a space, the first value will be assigned to the variable and the second value will be assigned to the variable at the next iteration of the loop and then the 3rd and so on. My question is how and where do these values get stored until they get assigned to the variable?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
