Friday, August 21, 2015

Java program to print alphabets


This program print alphabets on screen i.e a, b, c, ..., z. Here we print alphabets in lower case.

Java source code


class Alphabets
{
 public static void main(String args[])
 {
 char ch;
 
 for( ch = 'a' ; ch <= 'z' ; ch++ )
 System.out.println(ch);
 }
}

You can easily modify the above java program to print alphabets in upper case.

Output of program:


Printing alphabets using while loop (only body of main method is shown):
char c = 'a';
 
while (c <= 'z') {
 System.out.println(c);
 c++;
}

Using do while loop:
char c = 'A';
 
do {
 System.out.println(c);
 c++;
} while (c <= 'Z');

Related Posts:

  • Java if else Program Java if else program uses if else to execute statement(s) when a condition is fulfilled. Below is a simple program which explains the usage of if els… Read More
  • Java for loop Java for loop used to repeat execution of statement(s) until a certain condition holds true. for is a keyword in Java programming language. Java … Read More
  • How to get input from user in java This program tells you how to get input from user in a java program. We are using Scanner class to get input from user. This program firstly asks the… Read More
  • Java program print prime numbers This java program prints prime numbers, number of prime numbers required is asked from the user. Remember that smallest prime number is 2. … Read More
  • Enhanced for loop java Enhanced for loop java: Enhanced for loop is useful when scanning the array instead of using for loop. Syntax of enhanced for loop is: for (dat… Read More

0 Comments:

Post a Comment