Java程序显示从a到z的字母

编写一个Java程序,使用for循环、while循环和do-while循环显示从a到z的字母。在这个例子中,所有循环都从字母a迭代到z并显示它们作为输出。

public class Alphabetsatoz1 {
	public static void main(String[] args) {	
		char lwch;
		
		for(lwch = 'a'; lwch <= 'z'; lwch++) 
		{
			System.out.print(lwch + " ");
		}
		System.out.println();
		
		
		char lwch1 = 'a';
		while (lwch1 <= 'z') 
		{
			System.out.print(lwch1 + " ");
			lwch1++;
		}
		System.out.println();
		
		
		char lwch2 = 'a';
		do 
		{
			System.out.print(lwch2 + " ");
		} while (++lwch2 <= 'z');
	}
}
Java Program to Display Alphabets from a to z

这个程序显示从a到z的字母,它迭代ASCII码从97到122,分别代表字母a到z,并打印它们。

public class Example2 {

	public static void main(String[] args) {
			
		for(int i = 97; i <= 122; i++) 
		{
			System.out.printf("%c ", i);
		}
	}
}
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到z的字母的程序允许用户输入开始的小写字母,并打印到z的其余字母。

import java.util.Scanner;

public class Example3 {
	
	private static Scanner sc;

	public static void main(String[] args) {
			
		char ch, strlwChar;
		sc= new Scanner(System.in);

		System.out.print("Please Enter any Char =  ");
		strlwChar = sc.next().charAt(0);
		
		for(ch = strlwChar; ch <= 'z'; ch++) {
			System.out.print(ch + " ");
		}
	}
}
Please Enter any Char =  h
h i j k l m n o p q r s t u v w x y z