October 2017
Beginner
318 pages
7h 26m
English
Now, to finish off our program, all we need to do is print out our alpha array. To do this, let's make use of a nifty function in an always accessible object called Arrays. The Arrays.toString() function will convert a single dimension array, which is the kind of array that we've created, that is capable of being converted into a string:
public class Alphabet {
public static void main(String[] args) {
//97
char[] alpha = new char[26];
for(int i = 0; i < 26; i++)
{
alpha[i] = (char)(97 + i);
}
System.out.println(Arrays.toString(alpha));
}
}
Now, if we run our program, we'll see Java's representation of the English alphabet in array form:
If you have followed along with this, you should give yourself a solid pat on the ...
Read now
Unlock full access