Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2008, 2:19 PM   #1
Abyss
Newbie
 
Join Date: Apr 2005
Posts: 18
Rep Power: 0 Abyss is on a distinguished road
Pass integers to an array?

I'm trying to do something similar to passing a string to an array, as in the following piece of code:

String encryptMe = "Test"

char[] characters;
characters = encryptMe.toCharArray();

This is my attempt to do the same thing, only I'm trying to add numeric values to the array rather than characters. The errors I've got are "int cannot be dereferenced" and also "incompatiable types". I've read that ints can't be used in this case...though I've tried the same thing with long data types and got the same results.

int x;
int i;
char[] characters;
characters = encryptMe.toCharArray();
int[] numeric;

for (x=0; x<characters.length; x++)
	    {
	  int a = characters[x];
	  i = a - 96;
	  numeric = (int) i.toNumArray();
	    }

Any suggestions on how to achieve this the right way?

Thanks
Abyss is offline   Reply With Quote
Old Apr 4th, 2008, 3:40 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Pass integers to an array?

You seem to be approaching this problem from the perspective of a C programmer. Remember that arrays are actually objects in Java.

String encryptMe = "Test";
char[] characters = encryptMe.toCharArray();

int[] numeric = new int[characters.length];

for (int i = 0; i < characters.length; i++)
    numeric[i] = characters[i] - 96;
titaniumdecoy is offline   Reply With Quote
Old Apr 4th, 2008, 3:51 PM   #3
Abyss
Newbie
 
Join Date: Apr 2005
Posts: 18
Rep Power: 0 Abyss is on a distinguished road
Re: Pass integers to an array?

That's exactly what I was trying to do, thanks a lot titaniumdecoy!
Abyss is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
read integers from file into an array Simplesouljah C++ 28 Jan 24th, 2008 1:11 PM
tasm sorting 5 integers with array akioshin Assembly 15 Oct 30th, 2007 1:45 AM
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
changing size of an array Eric the Red Java 3 Apr 3rd, 2006 8:19 PM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC