1

I am in the process of learning java and have become quite stuck around arrays.

What I am trying to do is assign values to characters in an array. ie A = 0, B = 1, C = 2. Any help would be greatly be appreciated. Other questions similar to this haven't shown how to change A = 0 for exmaple.

 public class Conversion{

public static void main (String [] args)  {

String raw = "ABC";
int key = 3;

char[] list = raw.toCharArray();
int[] num = new int[raw.length()];

for (int i = 0; i < raw.length(); i++) {
num[i] = i + key;
}

System.out.print(num);




}
}

Thanks for the help,

Dave

  • What trouble do you have with the last code fragment? Have a string with all letters and return their representativ Index (charat) to get your value. Simply reassigning the values of a char doesn't work. – Andreas Brunnet Aug 14 '16 at 16:07
  • The system.out.print(num); spits out a few random numbers and letters. How do I return a representive index (charat)? Ideally I want to use an array to store these values because the string raw "ABC" will vastly change over time. Could contain up to 1000 characters for example. – Oldmanriver Aug 14 '16 at 22:18
  • I suggest you to go through some basic tutorials as they cover all that – Andreas Brunnet Aug 15 '16 at 04:49

0 Answers0