[Java] How to Prints Alphabets by Java Loops


Here you will see, How to prints Alphabets through Java all loops (for, While and do while). In these loops we are just increments char value and characters are increment continuously.

public class PrintAlphabets {

public static void main(String[] args) {
// By for Loop
char ch;
for (ch = 'a'; ch <= 'z'; ch++) {
System.out.print(ch + " ");
}
System.out.println();

// By While loop
char c = 'a';

while (c <= 'z') {
System.out.print(c + " ");
c++;
}
System.out.println();

// By do while loop
c = 'A';

do {
System.out.print(c + " ");
c++;
} while (c <= 'Z');
}

}

Output

a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

More

For more Algorithms and Java Programing Test questions and sample code follow below links

 

Advertisement

One thought on “[Java] How to Prints Alphabets by Java Loops”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s