Hi I want to create variables in Java within a for loop. Each variable should th
ID: 3625426 • Letter: H
Question
HiI want to create variables in Java within a for loop. Each variable should the be initialized as
Integer MyInt1
Integer MyInt2
Integer MyInt3
Integer MyInt4....
......
......
I want to create this variables using the variable(k) declared to manage the for loop.
Example
for(int k = 0; k< 10; k++)
{
Integer MyInt(k)
}
This must then initialize :
MyInt1
MyInt2
MyInt3
MyInt4....
...... as Integers
This above is what I want to accomplish but can't seem to find valid syntax to do this
Please help
Thanks in advance
Robert
Explanation / Answer
You cant create variables in a for loop without using an array because there is no way to change the name of the variable on the fly. But if you create an array then in essence it will be like what you have up there, but instead format of the name will look like MyInt[0], or whatever number your at.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.