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

 

Advertisements

About Saurabh Gupta

My Name is Saurabh Gupta, I have approx. 10 Year of experience in Information Technology World manly in Java/J2EE. During this time I have worked with multiple organization with different client, so many technology, frameworks etc.
This entry was posted in Algorithm, Data Structure, Java, Programming Test and tagged , , , , . Bookmark the permalink.

One Response to How to Prints Alphabets by Java Loops

  1. Pingback: Frequently Asked Algorithms and Programs in Interviews | Facing Issues On IT

Comments are closed.