Java Program to print English Alphabets between two Alphabets

Get two alphabets and print the alphabets lies between them.

Sample Input 1:

D H

Sample Ouput 1:

D E F G H

Program or Solution

				
			
					
import java.util.*;
class Alphabets
{
    public static void main(String args[])
    {
        char i;
	char start,stop;
        Scanner sc=new Scanner(System.in);	
        System.out.println("Enter Two Alphabets:");
	start=sc.next().charAt(0);
        stop=sc.next().charAt(0);
	System.out.println("The Output Is:");
	for(i=start;i<=stop;i++)
	  {
		System.out.print(" "+i);
	  }
    }
}
			
				
			

Program Explanation

for(i=start;i<=stop;i++)

i initialized with starting character and incremented by 1 at each iteration. iteration stops when i is greater than stop character.

printing i prints the character from start to stop.