> I need to make a program that simply displays the
> characters a to z. Should I assign each char to a
> number and then use a for() method to display each
> char assigned to the number until I hit number 26
> which z is assigned to?
You could do it that way, but you'd be jumping through some unnecessary hoops.
Example:
for (char c = 'a'; c <= 'z'; c++) System.out.print(c);
You could do it this way...
public class letters {
private char letters[];
public letters(){
// put all the letters in here that you need to display
letters = new char[] {'a','b','c','d','e'};
for(int i=0;i<letters.length;i++){
System.out.println(letters[i]);
}
}
public static void main(String[]args){
new letters();
}
}
>
> If the requirement is really that simple, don't spend
> a lot of time over-engineering a solution:
Agreed.
for(int i=0,j=0x4000000;j>>i!=1;System.out.print((char)(i+++97)));
> > If the requirement is really that simple, don't
> spend
> > a lot of time over-engineering a solution:
>
> Agreed.
> for(int i=0,j=0x4000000;j>>i!=1;System.out.print((char)(i+++97)));
I don't consider that proper obfuscation:for(long l=401311006719,i=5*13-1;(l>>>=1)!=0xBAD;System.out.print((char)(i+=l&1)));
kind regards,
Jos
I have NO clue what any of that means :P
I just need to print a to z by incrementing the letter with a value of one. I was thinking of assigning a to 1, b to 2, c to 3, and so forth all the way to 26 and then use a for() method to increment the char by one until I reach 26 or z. It does not have to be the most elegant method, just something that works. I will try it my way.