aspose file tools*
The moose likes Java in General and the fly likes Array Conversion Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array Conversion Help" Watch "Array Conversion Help" New topic
Author

Array Conversion Help

Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

Hello,

So I make an array and it will assign each element a number, I want to change the element numbers into words.

So say for example my code was the following:


int nums[] = { 2, 14, 18, 17, 76, 87, 58962 };

I know that the number 2 would be registered as nums[0] but I want it to be a number, not array syntax.


A: Is it possible to change the array number or whole syntax of the array into a word of some-kind.
B: If so, how do I do it?


Thanks,
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8398
    
  23

Dan Moody wrote:A: Is it possible to change the array number or whole syntax of the array into a word of some-kind.

Yes.
B: If so, how do I do it?

Well first you have to think through the rules of how we write out a number in longhand.

Taking the numbers you have currently in your array as examples, what do you want your program to print out?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

Winston Gutkowski wrote:
Dan Moody wrote:A: Is it possible to change the array number or whole syntax of the array into a word of some-kind.

Yes.
B: If so, how do I do it?

Well first you have to think through the rules of how we write out a number in longhand.

Taking the numbers you have currently in your array as examples, what do you want your program to print out?

Winston


Basically, I know that if want to get the number 2 from that array I will have to type nums[0] but I want to know how to change it so it says nums[insertwordhere] or something, I'm not too sure but I don't want it to be a number, I want the number to be a word.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Declare and assign an int variable insertWordHere to 0.

So now if you print nums[insertWordHere] it prints 2.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
But how many such variables do you want to declare? as many as the elements in the array? what words do you want to use?
Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

John Jai wrote:Declare and assign an int variable insertWordHere to 0.

So now if you print nums[insertWordHere] it prints 2.


Ah! Thank you sir!


While we're here, how would I import a variable from another file and use it,

before you start mocking me, I do know the code to import something, but its just a case of using the stuff inside it...

Assuming I had a file called DannyBoy in a package called golden.brown. So I know the code would be: import golden.brown.DannyBoy; and there was an int variable in there called InsertNumberHere, what exactly would I do to use that variable and the number assigned to it?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Dan Moody wrote:
John Jai wrote:before you start mocking me...

sorry, I thought I was helping you!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
If the variable InsertNumberHere in DannyBoy class is static, you can access it like DannyBoy.InsertNumberHere. If that's instance variable, create an object for DannyBoy and access with that.
Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

John Jai wrote:
Dan Moody wrote:
John Jai wrote:before you start mocking me...

sorry, I thought I was helping you!



No no, I meant it as in "before you start laughing at me because I don't know how to import" it just came out wrong.

but I am grateful for your help, honest
Dan Moody
Greenhorn

Joined: Feb 27, 2011
Posts: 20

John Jai wrote:If the variable InsertNumberHere in DannyBoy class is static, you can access it like DannyBoy.InsertNumberHere. If that's instance variable, create an object for DannyBoy and access with that.


Ahhhh, OK...

Thank you very much you guys are super friendly and polite...Waaaaay better and easier to understand than those guys over at StackOverflow....
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
John Jai wrote:If the variable InsertNumberHere in DannyBoy class is static, you can access it like DannyBoy.InsertNumberHere. If that's instance variable, create an object for DannyBoy and access with that.


what if the variable is declared as private?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Harsha Smith wrote:what if the variable is declared as private?

You are welcome to suggest the answer
 
 
subject: Array Conversion Help