java help
Author |
Message |
mendem03
|
Posted: Fri May 21, 2010 3:32 pm Post subject: java help |
|
|
i am new to java and i want to kow if you can give 1 variable multiply values were the user is not entering any of the values.
I know about arrays and they let the user enter multiply values but i dont know if i can put multiply values myself in the program |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Fri May 21, 2010 3:55 pm Post subject: Re: java help |
|
|
Um... What are you asking here? If you can store more than one value in a variable?
If it's an array, yes, you can. Java doesn't care where the information you store in variables comes from. Whether you read it from a file, get it from the user, or put it directly into the program doesn't matter.
For example:
Java: |
int[] myNumbers = new int[10];
myNumbers[1] = 2;
myNumbers[6] = 12;
|
|
|
|
|
|
|
mendem03
|
Posted: Fri May 21, 2010 4:35 pm Post subject: Re: java help |
|
|
Ya but i want to put it in a system.out.println command will it work in there |
|
|
|
|
|
TheGuardian001
|
Posted: Fri May 21, 2010 6:01 pm Post subject: Re: java help |
|
|
Um... Yes. Again, Java doesn't care where the data is coming from. To the JRE, there is absolutely no difference between data you program into your source code, get from the user, read from a file, etc.
System.out.println(varName[2]);
will output the third element of the array varName, regardless of how the value got put in that location. |
|
|
|
|
|
|
|