Need help with simple program

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?
[231 byte] By [Bopppera] at [2007-10-2 4:05:28]
# 1

> 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);

yawmarka at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 2

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();

}

}

>

Stonerose02a at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 3
> You could do it this way...A bit confusing: a class-name, a char-array and a method with the same name: letters.
prometheuzza at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 4
I know yeah, I have only just realised that and it is something that I would not normally do, but anyway it serves its purpose here to help this guy out.
Stonerose02a at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 5
If the requirement is really that simple, don't spend a lot of time over-engineering a solution:System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Dick_Adamsa at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 6

> 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)));

yawmarka at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 7
I don't agree
Stonerose02a at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 8

> > 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

JosAHa at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 9

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.

Bopppera at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...
# 10
> I have NO clue what any of that means :PHave a look at Yawmark's reply #1 (ignore his last reply and minefollowing it). It does exactly what you want.kind regards,Jos
JosAHa at 2007-7-15 23:28:12 > top of Java-index,Java Essentials,New To Java...