• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Conversion Help

 
Dan Moody
Greenhorn
Posts: 20
Chrome Debian Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10091
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Moody
Greenhorn
Posts: 20
Chrome Debian Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare and assign an int variable insertWordHere to 0.

So now if you print nums[insertWordHere] it prints 2.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Chrome Debian Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Moody wrote:
John Jai wrote:before you start mocking me...

sorry, I thought I was helping you!
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Chrome Debian Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Chrome Debian Eclipse IDE
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsha Smith wrote:what if the variable is declared as private?

You are welcome to suggest the answer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic