Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Need some help on array character sizes


Hi guys I'm stuck on a question on my java worksheet

Quote:5. Write a Java program to do the following:
• Declare an array of characters of size 26
• Use a for loop Fill the array with all the characters of the alphabet


I'm don't know how to go about setting the size of characters and am having trouble understanding the question kind of, can anyone help me out here? WOuld be much appreciated

As far as I know, arrays must have fixed size, so when you declare a new array you should specify the size of that array, and in this case you must declare an array of the size 26.

I think it goes somewhat like this :
Code
char[] myArray = new char[26];

About the second point. Well, I know how to use a loop but I just don't know yet how to make it assign the Alphabet letters one by one as elements of myArray, so I hope someone else in here can help you with that :)

Good Luck


EDIT :
Well, after a little search in Google, I managed to come up with this :
Code
public static void main(String[] args) {

  char[] myArray = new char[26];
  char c = 'a';
  for( int i = 0; i < 26 ; i++){
  System.out.println(c);
  myArray[i] = c++;
  }

    }

I hope this helps :)
Jon Stewart:
"In politics, it's ok to be a pussy as long as you have a dick"
Thank you very much ! :) helped alot



Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by gurlhackerclubMay 19, 2020 05:18 PM 8 260 May 19, 2020 05:18 PM
Last Post: k1r3n
[C#] by Bunnyslippers69Jan 7, 2020 02:49 PM 3 340 Jan 7, 2020 02:49 PM
Last Post: MavenGradle
[C] by TralenSep 9, 2017 05:13 PM 7 211 Sep 9, 2017 05:13 PM
Last Post: 0xDEAD10CC